summaryrefslogtreecommitdiffstats
path: root/js/vendor/angular-ui/templates/test/templateSpec.js
blob: 6eff729e150c5b15ae88326c3dcf3c2ef6fc3da9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * sample unit testing for sample templates and implementations
 */
describe('uiTemplate', function () {

  // declare these up here to be global to all tests
  var $rootScope, $compile;

  beforeEach(module('ui.directives'));
  beforeEach(module('ui.filters'));

  // inject in angular constructs. Injector knows about leading/trailing underscores and does the right thing
  // otherwise, you would need to inject these into each test
  beforeEach(inject(function (_$rootScope_, _$compile_) {
    $rootScope = _$rootScope_;
    $compile = _$compile_;
  }));

  // reset the ui.config after each test
  afterEach(function () {
    angular.module('ui.config').value('ui.config', {});
  });

  // optional grouping of tests
  describe('filter', function () {

    // we're doing filter tests so globally define here for this subset of tests
    var $filter;
    beforeEach(inject(function (_$filter_) {
      $filter = _$filter_;
    }));

    // very simple boilerplate setup of test for a custom filter
    var tmpl;
    beforeEach(function () {
      tmpl = $filter('filterTmpl');
    });

    it('should exist when provided', function () {
      expect(tmpl).toBeDefined();
    });

    it('should return exactly what interesting thing the filter is doing to input', function () {
      expect(tmpl('text')).toEqual('text');
    });

  });

  // optional grouping of tests
  describe('directive', function () {
    var element;
    it('should create an element if using element-style', function () {
      element = $compile('<ui-directive-tmpl ng-model="a"></ui-directive-tmpl>')($rootScope);
      expect(element).toBeDefined();
    });
  });

});