This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
/
Copy pathmatchersSpec.js
51 lines (46 loc) · 1.57 KB
/
matchersSpec.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
'use strict';
describe('angular.scenario.matchers', function() {
var matchers;
function expectMatcher(value, test) {
delete matchers.error;
delete matchers.future.value;
if (isDefined(value)) {
matchers.future.value = value;
}
test();
expect(matchers.error).toBeUndefined();
}
beforeEach(function() {
/**
* Mock up the future system wrapped around matchers.
*
* @see Scenario.js#angular.scenario.matcher
*/
matchers = {
future: { name: 'test' }
};
matchers.addFuture = function(name, callback) {
callback(function(error) {
matchers.error = error;
});
};
angular.extend(matchers, angular.scenario.matcher);
});
it('should handle basic matching', function() {
expectMatcher(10, function() { matchers.toEqual(10); });
expectMatcher('value', function() { matchers.toBeDefined(); });
expectMatcher([1], function() { matchers.toBeTruthy(); });
expectMatcher("", function() { matchers.toBeFalsy(); });
expectMatcher(0, function() { matchers.toBeFalsy(); });
expectMatcher('foo', function() { matchers.toMatch('.o.'); });
expectMatcher(null, function() { matchers.toBeNull(); });
expectMatcher([1, 2, 3], function() { matchers.toContain(2); });
expectMatcher(3, function() { matchers.toBeLessThan(10); });
expectMatcher(3, function() { matchers.toBeGreaterThan(-5); });
});
it('should have toHaveClass matcher', function() {
var e = angular.element('<div class="abc">');
expect(e).not.toHaveClass('none');
expect(e).toHaveClass('abc');
});
});