Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit cf33105

Browse files
Shyam Seshadrishyamseshadri
Shyam Seshadri
authored andcommitted
Fix toEqual matcher to use angular.equals instead of simple == comparison, which breaks down for arrays and objects
1 parent 04e92a8 commit cf33105

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

jsTestDriver.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ load:
88
- src/Angular.js
99
- src/JSON.js
1010
- src/*.js
11+
- test/testabilityPatch.js
1112
- src/scenario/Runner.js
1213
- src/scenario/*.js
13-
- test/testabilityPatch.js
1414
- test/angular-mocks.js
1515
- test/scenario/*.js
1616
- test/*.js

src/scenario/Matcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ Matcher.addMatcher = function(name, matcher) {
1818
};
1919
};
2020

21-
Matcher.addMatcher('toEqual', function(a,b) { return a == b; });
21+
Matcher.addMatcher('toEqual', angular.equals);

test/scenario/MatcherSpec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,12 @@ describe('Matcher', function () {
2727
expect(e).toEqual('Expected 456 but was 123');
2828
}
2929
});
30+
it('should correctly match arrays', function() {
31+
var future = $scenario.addFuture('Calculate first future', function(done) {
32+
done(['a', 'b']);
33+
});
34+
matcher = new Matcher(this, future);
35+
matcher.toEqual(['a', 'b']);
36+
executeFutures();
37+
});
3038
});

test/testabilityPatch.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,25 @@ function childNode(element, index) {
3535
}
3636

3737
extend(angular, {
38-
'bind': bind,
38+
'element': jqLite,
3939
'compile': compile,
40+
'scope': createScope,
4041
'copy': copy,
41-
'element': jqLite,
4242
'extend': extend,
43+
'equals': equals,
4344
'foreach': foreach,
45+
'noop':noop,
46+
'bind':bind,
47+
'toJson': toJson,
48+
'fromJson': fromJson,
4449
'identity':identity,
4550
'isUndefined': isUndefined,
4651
'isDefined': isDefined,
47-
'isObject': isObject,
4852
'isString': isString,
4953
'isFunction': isFunction,
54+
'isObject': isObject,
5055
'isNumber': isNumber,
51-
'isArray': isArray,
52-
'noop':noop,
53-
'scope': createScope
56+
'isArray': isArray
5457
});
5558

5659

0 commit comments

Comments
 (0)