forked from cironunes/angular-testing-recipes
-
Notifications
You must be signed in to change notification settings - Fork 7
/
helpers.js
85 lines (75 loc) · 2.41 KB
/
helpers.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
80
81
82
83
84
85
// jasmine matcher for expecting an element to have a css class
// https://github.com/angular/angular.js/blob/master/test/matchers.js
beforeEach(function() {
jasmine.addMatchers({
toBeInstanceOf: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
var notText = this.isNot ? ' not' : '';
var result = {
pass: actual instanceof expected
};
result.message = 'Expected ' + actual.constructor.name + notText + ' is instance of ' + expected.name;
return result;
}
};
},
toBeTypeOf: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
var notText = this.isNot ? ' not' : '';
var result = {
pass: typeof actual === expected
};
result.message = 'Expected ' + (typeof actual) + notText + ' to be type of ' + (typeof expected);
return result;
}
};
},
toHaveClass: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
var result = {
pass: actual.hasClass(expected)
};
if (result.pass) {
result.message = 'Expected "' + actual + '" not to have the "' + expected + '" class.';
} else {
result.message = 'Expected "' + actual + '" to have the "' + expected + '" class.';
}
return result;
}
}
},
toBeHidden: function(util, customEqualityTesters) {
return {
compare: function(actual) {
var result = {
pass: actual.hasClass('ng-hide') || actual.css('display') === 'none'
};
if (result.pass) {
result.message = 'Expected "' + actual + '" not to be hidden';
} else {
result.message = 'Expected "' + actual + '" to be hidden';
}
return result;
}
}
},
toHaveFocus: function(util, customEqualityTesters) {
return {
compare: function(actual) {
var result = {
pass: document.activeElement === actual[0]
};
if (result.pass) {
result.message = 'Expected "' + actual + '" not to have focus';
} else {
result.message = 'Expected "' + actual + '" to have focus';
}
return result;
}
}
}
});
});