-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdirective-link-with-test-element.js
80 lines (68 loc) · 1.81 KB
/
directive-link-with-test-element.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function someDirective() {
var directive = {
restrict: 'E',
replace: true,
templateUrl: 'examples/TestElement/template.html',
scope: {
someArray: '='
},
link: function(scope) {
scope.addToArray = function(name) {
var item = {};
item.id = scope.someArray.length + 1;
item.name = name;
scope.someArray.push(item);
};
}
};
return directive;
}
angular
.module('directiveLinkWithTE', [])
.directive('someDirective', someDirective);
describe('someDirective', function() {
var
element, $compile, $rootScope, $scope,
namesArray = [{
id: 1,
name: 'Name1'
}, {
id: 2,
name: 'Name2'
}, {
id: 3,
name: 'Name3'
}];
beforeEach(module('directiveLinkWithTE'));
beforeEach(module('templates'));
beforeEach(function() {
element = new TestElement();
element.createDirective('someDirective', '<some-directive some-array="namesArray"></some-directive>', {
namesArray: namesArray
});
});
it('should not be null', function() {
expect(element.dom).toBeTruthy();
});
it('should show 3 span elements', function() {
expect(element.findAll('span').length).toBe(3);
});
describe('button', function() {
it('should have .button class', function() {
expect(element.find('button').hasClass('button')).toBeTruthy();
});
});
describe('Add new item', function() {
var newVal = 'newName';
beforeEach(function() {
element.inputOn('.new-item', newVal, 1).then(function() {
element.clickOn('.button');
});
});
it('should add new element to array', function() {
expect(element.findAll('span').length).toBe(4);
expect(element.dom.text()).toContain(newVal);
expect(element.scope.someArray[3].id).toBe(4);
});
});
});