Merge branch 'master' into 3.0-features
This commit is contained in:
@@ -7,9 +7,7 @@ Follow the instructions in `CONTRIBUTING.md` during development.
|
||||
|
||||
### Git Rules
|
||||
|
||||
Please work on feature branches.
|
||||
|
||||
Please attempt to keep commits to `master` small, but cohesive. If a feature is contained in a bunch of small commits (e.g., it has several wip commits or small work), please squash them when merging back to `master`.
|
||||
Please attempt to keep commits to `master` small, but cohesive. If a feature is contained in a bunch of small commits (e.g., it has several wip commits or small work), please squash them when pushing to `master`.
|
||||
|
||||
### Version
|
||||
|
||||
|
||||
@@ -237,6 +237,14 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
return obj.nodeType > 0;
|
||||
};
|
||||
|
||||
j$.isMap = function(obj) {
|
||||
return typeof jasmineGlobal.Map !== 'undefined' && obj.constructor === jasmineGlobal.Map;
|
||||
};
|
||||
|
||||
j$.isSet = function(obj) {
|
||||
return typeof jasmineGlobal.Set !== 'undefined' && obj.constructor === jasmineGlobal.Set;
|
||||
};
|
||||
|
||||
j$.isPromise = function(obj) {
|
||||
return typeof jasmineGlobal.Promise !== 'undefined' && obj.constructor === jasmineGlobal.Promise;
|
||||
};
|
||||
@@ -2251,6 +2259,7 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
|
||||
}
|
||||
|
||||
do {
|
||||
deletedKeys = [];
|
||||
var newCurrentTime = scheduledLookup.shift();
|
||||
tickDate(newCurrentTime - currentTime);
|
||||
|
||||
@@ -2806,7 +2815,7 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
diffBuilder.record(a, b);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
var aIsPromise = j$.isPromise(a);
|
||||
var bIsPromise = j$.isPromise(b);
|
||||
if (aIsPromise && bIsPromise) {
|
||||
@@ -2846,26 +2855,34 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
} else if (className == '[object Map]') {
|
||||
} else if (j$.isMap(a) && j$.isMap(b)) {
|
||||
if (a.size != b.size) {
|
||||
diffBuilder.record(a, b);
|
||||
return false;
|
||||
}
|
||||
|
||||
var keysA = [];
|
||||
var keysB = [];
|
||||
a.forEach( function( valueA, keyA ) {
|
||||
keysA.push( keyA );
|
||||
});
|
||||
b.forEach( function( valueB, keyB ) {
|
||||
keysB.push( keyB );
|
||||
});
|
||||
|
||||
// For both sets of keys, check they map to equal values in both maps.
|
||||
// Keep track of corresponding keys (in insertion order) in order to handle asymmetric obj keys.
|
||||
var mapKeys = [a.keys(), b.keys()];
|
||||
var cmpKeys = [b.keys(), a.keys()];
|
||||
var mapIter, mapKeyIt, mapKey, mapValueA, mapValueB;
|
||||
var cmpIter, cmpKeyIt, cmpKey;
|
||||
var mapKeys = [keysA, keysB];
|
||||
var cmpKeys = [keysB, keysA];
|
||||
var mapIter, mapKey, mapValueA, mapValueB;
|
||||
var cmpIter, cmpKey;
|
||||
for (i = 0; result && i < mapKeys.length; i++) {
|
||||
mapIter = mapKeys[i];
|
||||
cmpIter = cmpKeys[i];
|
||||
mapKeyIt = mapIter.next();
|
||||
cmpKeyIt = cmpIter.next();
|
||||
while (result && !mapKeyIt.done) {
|
||||
mapKey = mapKeyIt.value;
|
||||
cmpKey = cmpKeyIt.value;
|
||||
|
||||
for (var j = 0; result && j < mapIter.length; j++) {
|
||||
mapKey = mapIter[j];
|
||||
cmpKey = cmpIter[j];
|
||||
mapValueA = a.get(mapKey);
|
||||
|
||||
// Only use the cmpKey when one of the keys is asymmetric and the corresponding key matches,
|
||||
@@ -2878,8 +2895,6 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
mapValueB = b.get(mapKey);
|
||||
}
|
||||
result = eq(mapValueA, mapValueB, aStack, bStack, customTesters, j$.NullDiffBuilder());
|
||||
mapKeyIt = mapIter.next();
|
||||
cmpKeyIt = cmpIter.next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2887,48 +2902,49 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
diffBuilder.record(a, b);
|
||||
return false;
|
||||
}
|
||||
} else if (className == '[object Set]') {
|
||||
} else if (j$.isSet(a) && j$.isSet(b)) {
|
||||
if (a.size != b.size) {
|
||||
diffBuilder.record(a, b);
|
||||
return false;
|
||||
}
|
||||
|
||||
var valuesA = [];
|
||||
a.forEach( function( valueA ) {
|
||||
valuesA.push( valueA );
|
||||
});
|
||||
var valuesB = [];
|
||||
b.forEach( function( valueB ) {
|
||||
valuesB.push( valueB );
|
||||
});
|
||||
|
||||
// For both sets, check they are all contained in the other set
|
||||
var setPairs = [[a, b], [b, a]];
|
||||
var setPairs = [[valuesA, valuesB], [valuesB, valuesA]];
|
||||
var stackPairs = [[aStack, bStack], [bStack, aStack]];
|
||||
var baseIter, baseValueIt, baseValue, baseStack;
|
||||
var otherSet, otherIter, otherValueIt, otherValue, otherStack;
|
||||
var baseValues, baseValue, baseStack;
|
||||
var otherValues, otherValue, otherStack;
|
||||
var found;
|
||||
var prevStackSize;
|
||||
for (i = 0; result && i < setPairs.length; i++) {
|
||||
baseIter = setPairs[i][0].values();
|
||||
otherSet = setPairs[i][1];
|
||||
baseValues = setPairs[i][0];
|
||||
otherValues = setPairs[i][1];
|
||||
baseStack = stackPairs[i][0];
|
||||
otherStack = stackPairs[i][1];
|
||||
// For each value in the base set...
|
||||
baseValueIt = baseIter.next();
|
||||
while (result && !baseValueIt.done) {
|
||||
baseValue = baseValueIt.value;
|
||||
for (var k = 0; result && k < baseValues.length; k++) {
|
||||
baseValue = baseValues[k];
|
||||
found = false;
|
||||
// ... test that it is present in the other set
|
||||
// Optimisation: start looking for value by object identity
|
||||
found = otherSet.has(baseValue);
|
||||
if (!found) {
|
||||
otherIter = otherSet.values();
|
||||
otherValueIt = otherIter.next();
|
||||
}
|
||||
// If not found, compare by value equality
|
||||
while (!found && !otherValueIt.done) {
|
||||
otherValue = otherValueIt.value;
|
||||
for (var l = 0; !found && l < otherValues.length; l++) {
|
||||
otherValue = otherValues[l];
|
||||
prevStackSize = baseStack.length;
|
||||
// compare by value equality
|
||||
found = eq(baseValue, otherValue, baseStack, otherStack, customTesters, j$.NullDiffBuilder());
|
||||
if (!found && prevStackSize !== baseStack.length) {
|
||||
baseStack.splice(prevStackSize);
|
||||
otherStack.splice(prevStackSize);
|
||||
}
|
||||
otherValueIt = otherIter.next();
|
||||
}
|
||||
result = result && found;
|
||||
baseValueIt = baseIter.next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4184,9 +4200,9 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
this.emitScalar('HTMLNode');
|
||||
} else if (value instanceof Date) {
|
||||
this.emitScalar('Date(' + value + ')');
|
||||
} else if (j$.getType_(value) == '[object Set]') {
|
||||
} else if (j$.isSet(value)) {
|
||||
this.emitSet(value);
|
||||
} else if (j$.getType_(value) == '[object Map]') {
|
||||
} else if (j$.isMap(value)) {
|
||||
this.emitMap(value);
|
||||
} else if (j$.isTypedArray_(value)) {
|
||||
this.emitTypedArray(value);
|
||||
@@ -4283,13 +4299,18 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
}
|
||||
this.append('Set( ');
|
||||
var size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||
var iter = set.values();
|
||||
for (var i = 0; i < size; i++) {
|
||||
var i = 0;
|
||||
set.forEach( function( value, key ) {
|
||||
if (i >= size) {
|
||||
return;
|
||||
}
|
||||
if (i > 0) {
|
||||
this.append(', ');
|
||||
}
|
||||
this.format(iter.next().value);
|
||||
}
|
||||
this.format(value);
|
||||
|
||||
i++;
|
||||
}, this );
|
||||
if (set.size > size){
|
||||
this.append(', ...');
|
||||
}
|
||||
@@ -4303,13 +4324,18 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
}
|
||||
this.append('Map( ');
|
||||
var size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||
var iter = map.entries();
|
||||
for (var i = 0; i < size; i++) {
|
||||
var i = 0;
|
||||
map.forEach( function( value, key ) {
|
||||
if (i >= size) {
|
||||
return;
|
||||
}
|
||||
if (i > 0) {
|
||||
this.append(', ');
|
||||
}
|
||||
this.format(iter.next().value);
|
||||
}
|
||||
this.format([key,value]);
|
||||
|
||||
i++;
|
||||
}, this );
|
||||
if (map.size > size){
|
||||
this.append(', ...');
|
||||
}
|
||||
|
||||
99
release_notes/2.9.0.md
Normal file
99
release_notes/2.9.0.md
Normal file
@@ -0,0 +1,99 @@
|
||||
# Jasmine 2.9 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This release contains a number of fixes and pull requests.
|
||||
|
||||
## Changes
|
||||
|
||||
* Fixed DelayedFunctionScheduler IE 8 compatibility issue
|
||||
* Fixed SPEC HAS NO EXPECTATIONS warning in HTML reporter
|
||||
* Correctly remove spies of window.onerror on IE
|
||||
* Truncate pretty printer output that is more than j$.MAX_PRETTY_PRINT_CHARS long
|
||||
* Reduced pretty printer limits to much smaller values
|
||||
* Update contributing for new naming of `jasmineUnderTest`
|
||||
* Allowed async functions to be passed into spy#callFake
|
||||
|
||||
## Pull Requests & Issues
|
||||
|
||||
* Added complete support for Set also for IE11.
|
||||
- Merges [#1478](https://github.com/jasmine/jasmine/issues/1478) from @Volox
|
||||
- Fixes [#1355](https://github.com/jasmine/jasmine/issues/1355)
|
||||
|
||||
|
||||
* Added complete support for Map also for IE11.
|
||||
- Merges [#1477](https://github.com/jasmine/jasmine/issues/1477) from @Volox
|
||||
- Fixes [#1472](https://github.com/jasmine/jasmine/issues/1472)
|
||||
|
||||
|
||||
* Use timeout objects when in node
|
||||
- Merges [#1470](https://github.com/jasmine/jasmine/issues/1470) from @chris--young
|
||||
- Fixes [#1469](https://github.com/jasmine/jasmine/issues/1469)
|
||||
|
||||
|
||||
* Fixed `pending()` for `async`/promise-returning specs
|
||||
- Fixes [#1449](https://github.com/jasmine/jasmine/issues/1449)
|
||||
- Fixes [#1450](https://github.com/jasmine/jasmine/issues/1450)
|
||||
|
||||
|
||||
* Added test steps for other major node versions
|
||||
- Merges [#1448](https://github.com/jasmine/jasmine/issues/1448) from @mrlannigan
|
||||
|
||||
|
||||
* Fix equality computation for ES6 Sets.
|
||||
- Merges [#1445](https://github.com/jasmine/jasmine/issues/1445) from @b-3-n
|
||||
- Fixes [#1444](https://github.com/jasmine/jasmine/issues/1444)
|
||||
|
||||
|
||||
* Add instruction to sync local master with upstream
|
||||
- Merges [#1440](https://github.com/jasmine/jasmine/issues/1440) from aaronang
|
||||
|
||||
|
||||
* Add some unit tests that exercise jasmine.anything() and Map matching.
|
||||
- Merges [#1437](https://github.com/jasmine/jasmine/issues/1437) from @voithos
|
||||
|
||||
|
||||
* Add special handling of asymmetric matcher objects as keys in Maps.
|
||||
- Merges [#1436](https://github.com/jasmine/jasmine/issues/1436) from @voithos
|
||||
- Fixes [#1432](https://github.com/jasmine/jasmine/issues/1432)
|
||||
|
||||
|
||||
* Add support for jasmine.any(Symbol).
|
||||
- Merge [#1435](https://github.com/jasmine/jasmine/issues/1435) from @voithos
|
||||
- Fixes [#1431](https://github.com/jasmine/jasmine/issues/1431)
|
||||
|
||||
|
||||
* Throw an error for invalid nesting of a suite functions
|
||||
- Merges [#1411](https://github.com/jasmine/jasmine/issues/1411) from @ksvitkovsky
|
||||
- Fixes [#1295](https://github.com/jasmine/jasmine/issues/1295)
|
||||
|
||||
|
||||
* Deep clone args before passing them to reporters
|
||||
- Merges [#1424](https://github.com/jasmine/jasmine/issues/1424) from @aj-dev
|
||||
|
||||
|
||||
* Fix "Before Committing" section of CONTRIBUTING.md.
|
||||
- Merges [#1429](https://github.com/jasmine/jasmine/issues/1429) from @voithos
|
||||
|
||||
|
||||
* Fix lint warning in CallTracker.
|
||||
- Merges [#1428](https://github.com/jasmine/jasmine/issues/1428) from @voithos
|
||||
|
||||
|
||||
* clearTimeout should now correctly clear a timeout that is also scheduled to run at the same tick.
|
||||
- Merges [#1427](https://github.com/jasmine/jasmine/issues/1427) from @leahciMic
|
||||
- Fixes [#1426](https://github.com/jasmine/jasmine/issues/1426)
|
||||
|
||||
|
||||
* Add a note about `defineProperty` for `spyOnProperty`
|
||||
- Fixes [#1415](https://github.com/jasmine/jasmine/issues/1415)
|
||||
|
||||
|
||||
* Add Promise checking to eq
|
||||
- Merges [#1386](https://github.com/jasmine/jasmine/issues/1386) from @sderickson
|
||||
- Fixes [#1314](https://github.com/jasmine/jasmine/issues/1314)
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
15
release_notes/2.9.1.md
Normal file
15
release_notes/2.9.1.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Jasmine Core 2.9.1 Release Notes
|
||||
|
||||
## Summary
|
||||
|
||||
This is a hotfix release to fix a breaking change from the 2.9.0 release
|
||||
|
||||
## Changes
|
||||
|
||||
* Clear timeouts when starting to process a milli instead of at the end
|
||||
- Fixes #1482
|
||||
|
||||
|
||||
------
|
||||
|
||||
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
|
||||
@@ -254,6 +254,22 @@ describe("DelayedFunctionScheduler", function() {
|
||||
expect(fn.calls.count()).toBe(1);
|
||||
});
|
||||
|
||||
it("does not remove a function that hasn't been added yet", function() {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
fn = jasmine.createSpy('fn'),
|
||||
fnDelay = 10,
|
||||
timeoutKey;
|
||||
|
||||
scheduler.removeFunctionWithId('foo');
|
||||
scheduler.scheduleFunction(fn, fnDelay, [], false, 'foo');
|
||||
|
||||
expect(fn).not.toHaveBeenCalled();
|
||||
|
||||
scheduler.tick(fnDelay + 1);
|
||||
|
||||
expect(fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("updates the mockDate per scheduled time", function () {
|
||||
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
tickDate = jasmine.createSpy('tickDate');
|
||||
|
||||
@@ -17,7 +17,10 @@ describe("jasmineUnderTest.pp", function () {
|
||||
describe('stringify sets', function() {
|
||||
it("should stringify sets properly", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
expect(jasmineUnderTest.pp(new Set([1, 2]))).toEqual("Set( 1, 2 )");
|
||||
var set = new Set();
|
||||
set.add(1);
|
||||
set.add(2);
|
||||
expect(jasmineUnderTest.pp(set)).toEqual("Set( 1, 2 )");
|
||||
});
|
||||
|
||||
it("should truncate sets with more elments than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH", function() {
|
||||
@@ -26,7 +29,11 @@ describe("jasmineUnderTest.pp", function () {
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
expect(jasmineUnderTest.pp(new Set(["a", "b", "c"]))).toEqual("Set( 'a', 'b', ... )");
|
||||
var set = new Set();
|
||||
set.add('a');
|
||||
set.add('b');
|
||||
set.add('c');
|
||||
expect(jasmineUnderTest.pp(set)).toEqual("Set( 'a', 'b', ... )");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||
}
|
||||
@@ -36,7 +43,9 @@ describe("jasmineUnderTest.pp", function () {
|
||||
describe('stringify maps', function() {
|
||||
it("should stringify maps properly", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
expect(jasmineUnderTest.pp(new Map([[1, 2]]))).toEqual("Map( [ 1, 2 ] )");
|
||||
var map = new Map();
|
||||
map.set(1,2);
|
||||
expect(jasmineUnderTest.pp(map)).toEqual("Map( [ 1, 2 ] )");
|
||||
});
|
||||
|
||||
it("should truncate maps with more elments than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH", function() {
|
||||
@@ -45,7 +54,11 @@ describe("jasmineUnderTest.pp", function () {
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
expect(jasmineUnderTest.pp(new Map([["a", 1], ["b", 2], ["c", 3]]))).toEqual("Map( [ 'a', 1 ], [ 'b', 2 ], ... )");
|
||||
var map = new Map();
|
||||
map.set("a",1);
|
||||
map.set("b",2);
|
||||
map.set("c",3);
|
||||
expect(jasmineUnderTest.pp(map)).toEqual("Map( [ 'a', 1 ], [ 'b', 2 ], ... )");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||
}
|
||||
@@ -120,15 +133,15 @@ describe("jasmineUnderTest.pp", function () {
|
||||
});
|
||||
|
||||
it("should truncate objects with too many keys", function () {
|
||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
var long = {a: 1, b: 2, c: 3};
|
||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
var long = {a: 1, b: 2, c: 3};
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
expect(jasmineUnderTest.pp(long)).toEqual("Object({ a: 1, b: 2, ... })");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
||||
}
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
expect(jasmineUnderTest.pp(long)).toEqual("Object({ a: 1, b: 2, ... })");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
||||
}
|
||||
});
|
||||
|
||||
function withMaxChars(maxChars, fn) {
|
||||
@@ -251,9 +264,9 @@ describe("jasmineUnderTest.pp", function () {
|
||||
|
||||
it("should stringify spy objects properly", function() {
|
||||
var TestObject = {
|
||||
someFunction: function() {}
|
||||
},
|
||||
env = new jasmineUnderTest.Env();
|
||||
someFunction: function() {}
|
||||
},
|
||||
env = new jasmineUnderTest.Env();
|
||||
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {return [];},
|
||||
|
||||
@@ -48,7 +48,7 @@ describe("Anything", function() {
|
||||
});
|
||||
|
||||
it("matches a Symbol", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
|
||||
var anything = new jasmineUnderTest.Anything();
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("fails for Arrays whose contents are equivalent, but have differing properties", function() {
|
||||
var one = [1,2,3],
|
||||
two = [1,2,3];
|
||||
two = [1,2,3];
|
||||
|
||||
one.foo = 'bar';
|
||||
two.foo = 'baz';
|
||||
@@ -81,7 +81,7 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes for Arrays with equivalent contents and properties", function() {
|
||||
var one = [1,2,3],
|
||||
two = [1,2,3];
|
||||
two = [1,2,3];
|
||||
|
||||
one.foo = 'bar';
|
||||
two.foo = 'bar';
|
||||
@@ -122,7 +122,7 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes for Objects that are equivalent (with cycles)", function() {
|
||||
var actual = { a: "foo" },
|
||||
expected = { a: "foo" };
|
||||
expected = { a: "foo" };
|
||||
|
||||
actual.b = actual;
|
||||
expected.b = actual;
|
||||
@@ -336,7 +336,7 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes for an asymmetric equality tester that returns true when a custom equality tester return false", function() {
|
||||
var asymmetricTester = { asymmetricMatch: function(other) { return true; } },
|
||||
symmetricTester = function(a, b) { return false; };
|
||||
symmetricTester = function(a, b) { return false; };
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true);
|
||||
@@ -354,14 +354,14 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes when an Any is compared to an Any that checks for the same type", function() {
|
||||
var any1 = new jasmineUnderTest.Any(Function),
|
||||
any2 = new jasmineUnderTest.Any(Function);
|
||||
any2 = new jasmineUnderTest.Any(Function);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(any1, any2)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes for null prototype objects with same properties", function () {
|
||||
var objA = Object.create(null),
|
||||
objB = Object.create(null);
|
||||
objB = Object.create(null);
|
||||
|
||||
objA.name = 'test';
|
||||
objB.name = 'test';
|
||||
@@ -371,7 +371,7 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("fails for null prototype objects with different properties", function () {
|
||||
var objA = Object.create(null),
|
||||
objB = Object.create(null);
|
||||
objB = Object.create(null);
|
||||
|
||||
objA.name = 'test';
|
||||
objB.test = 'name';
|
||||
@@ -386,45 +386,94 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes when comparing identical sets", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var setA = new Set([6, 5]);
|
||||
|
||||
var setA = new Set();
|
||||
setA.add(6);
|
||||
setA.add(5);
|
||||
var setB = new Set();
|
||||
setB.add(6);
|
||||
setB.add(5);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical sets with different insertion order and simple elements", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var setA = new Set([3, 6]);
|
||||
var setB = new Set([6, 3]);
|
||||
|
||||
var setA = new Set();
|
||||
setA.add(3);
|
||||
setA.add(6);
|
||||
var setB = new Set();
|
||||
setB.add(6);
|
||||
setB.add(3);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical sets with different insertion order and complex elements 1", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var setA = new Set([new Set([['a', 3], [6, 1]]), new Set([['y', 3], [6, 1]])]);
|
||||
var setB = new Set([new Set([[6, 1], ['a', 3]]), new Set([[6, 1], ['y', 3]])]);
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var setA1 = new Set();
|
||||
setA1.add(['a',3]);
|
||||
setA1.add([6,1]);
|
||||
var setA2 = new Set();
|
||||
setA1.add(['y',3]);
|
||||
setA1.add([6,1]);
|
||||
var setA = new Set();
|
||||
setA.add(setA1);
|
||||
setA.add(setA2);
|
||||
|
||||
|
||||
var setB1 = new Set();
|
||||
setB1.add([6,1]);
|
||||
setB1.add(['a',3]);
|
||||
var setB2 = new Set();
|
||||
setB1.add([6,1]);
|
||||
setB1.add(['y',3]);
|
||||
var setB = new Set();
|
||||
setB.add(setB1);
|
||||
setB.add(setB2);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
||||
});
|
||||
|
||||
it("passes when comparing identical sets with different insertion order and complex elements 2", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var setA = new Set([[[1,2], [3,4]], [[5,6], [7,8]]]);
|
||||
var setB = new Set([[[5,6], [7,8]], [[1,2], [3,4]]]);
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var setA = new Set();
|
||||
setA.add([[1,2], [3,4]]);
|
||||
setA.add([[5,6], [7,8]]);
|
||||
var setB = new Set();
|
||||
setB.add([[5,6], [7,8]]);
|
||||
setB.add([[1,2], [3,4]]);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for sets with different elements", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var setA = new Set([6, 3, 5]);
|
||||
var setB = new Set([6, 4, 5]);
|
||||
var setA = new Set();
|
||||
setA.add(6);
|
||||
setA.add(3);
|
||||
setA.add(5);
|
||||
var setB = new Set();
|
||||
setB.add(6);
|
||||
setB.add(4);
|
||||
setB.add(5);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for sets of different size", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
var setA = new Set([6, 3]);
|
||||
var setB = new Set([6, 4, 5]);
|
||||
var setA = new Set();
|
||||
setA.add(6);
|
||||
setA.add(3);
|
||||
var setB = new Set();
|
||||
setB.add(6);
|
||||
setB.add(4);
|
||||
setB.add(5);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
|
||||
});
|
||||
|
||||
@@ -435,7 +484,8 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes when comparing identical maps", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var mapA = new Map([[6, 5]]);
|
||||
var mapA = new Map();
|
||||
mapA.set(6, 5);
|
||||
var mapB = new Map();
|
||||
mapB.set(6, 5);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
||||
@@ -443,22 +493,34 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes when comparing identical maps with different insertion order", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var mapA = new Map([['a', 3], [6, 1]]);
|
||||
var mapB = new Map([[6, 1], ['a', 3]]);
|
||||
var mapA = new Map();
|
||||
mapA.set("a", 3);
|
||||
mapA.set(6, 1);
|
||||
var mapB = new Map();
|
||||
mapB.set(6, 1);
|
||||
mapB.set("a", 3);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
||||
});
|
||||
|
||||
it("fails for maps with different elements", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var mapA = new Map([[6, 3], [5, 1]]);
|
||||
var mapB = new Map([[6, 4], [5, 1]]);
|
||||
var mapA = new Map();
|
||||
mapA.set(6, 3);
|
||||
mapA.set(5, 1);
|
||||
var mapB = new Map();
|
||||
mapB.set(6, 4);
|
||||
mapB.set(5, 1);
|
||||
|
||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for maps of different size", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var mapA = new Map([[6, 3]]);
|
||||
var mapB = new Map([[6, 4], [5, 1]]);
|
||||
var mapA = new Map();
|
||||
mapA.set(6, 3);
|
||||
var mapB = new Map();
|
||||
mapB.set(6, 4);
|
||||
mapB.set(5, 1);
|
||||
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
||||
});
|
||||
|
||||
@@ -472,28 +534,28 @@ describe("matchersUtil", function() {
|
||||
Object.defineProperty(Array.prototype, 'findIndex', {
|
||||
enumerable: true,
|
||||
value: function (predicate) {
|
||||
if (this === null) {
|
||||
throw new TypeError('Array.prototype.findIndex called on null or undefined');
|
||||
}
|
||||
if (this === null) {
|
||||
throw new TypeError('Array.prototype.findIndex called on null or undefined');
|
||||
}
|
||||
|
||||
if (typeof predicate !== 'function') {
|
||||
throw new TypeError('predicate must be a function');
|
||||
}
|
||||
if (typeof predicate !== 'function') {
|
||||
throw new TypeError('predicate must be a function');
|
||||
}
|
||||
|
||||
var list = Object(this);
|
||||
var length = list.length >>> 0;
|
||||
var thisArg = arguments[1];
|
||||
var value;
|
||||
var list = Object(this);
|
||||
var length = list.length >>> 0;
|
||||
var thisArg = arguments[1];
|
||||
var value;
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
value = list[i];
|
||||
if (predicate.call(thisArg, value, i, list)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < length; i++) {
|
||||
value = list[i];
|
||||
if (predicate.call(thisArg, value, i, list)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -355,9 +355,11 @@ describe("toEqual", function() {
|
||||
it("reports mismatches between Sets", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var actual = new Set([1]),
|
||||
expected = new Set([2]),
|
||||
message = 'Expected Set( 1 ) to equal Set( 2 ).';
|
||||
var actual = new Set();
|
||||
actual.add(1);
|
||||
var expected = new Set();
|
||||
expected.add(2);
|
||||
var message = 'Expected Set( 1 ) to equal Set( 2 ).';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -365,9 +367,11 @@ describe("toEqual", function() {
|
||||
it("reports deep mismatches within Sets", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var actual = new Set([{x: 1}]),
|
||||
expected = new Set([{x: 2}]),
|
||||
message = 'Expected Set( Object({ x: 1 }) ) to equal Set( Object({ x: 2 }) ).';
|
||||
var actual = new Set();
|
||||
actual.add({x: 1});
|
||||
var expected = new Set();
|
||||
expected.add({x: 2});
|
||||
var message = 'Expected Set( Object({ x: 1 }) ) to equal Set( Object({ x: 2 }) ).';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -375,9 +379,14 @@ describe("toEqual", function() {
|
||||
it("reports mismatches between Sets nested in objects", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var actual = {sets: [new Set([1])]},
|
||||
expected = {sets: [new Set([2])]},
|
||||
message = "Expected $.sets[0] = Set( 1 ) to equal Set( 2 ).";
|
||||
var actualSet = new Set();
|
||||
actualSet.add(1);
|
||||
var expectedSet = new Set();
|
||||
expectedSet.add(2);
|
||||
|
||||
var actual = { sets: [actualSet] };
|
||||
var expected = { sets: [expectedSet] };
|
||||
var message = "Expected $.sets[0] = Set( 1 ) to equal Set( 2 ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -385,9 +394,12 @@ describe("toEqual", function() {
|
||||
it("reports mismatches between Sets of different lengths", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var actual = new Set([1, 2]),
|
||||
expected = new Set([2]),
|
||||
message = 'Expected Set( 1, 2 ) to equal Set( 2 ).';
|
||||
var actual = new Set();
|
||||
actual.add(1);
|
||||
actual.add(2);
|
||||
var expected = new Set();
|
||||
expected.add(2);
|
||||
var message = 'Expected Set( 1, 2 ) to equal Set( 2 ).';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -396,9 +408,13 @@ describe("toEqual", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
// Use 'duplicate' object in actual so sizes match
|
||||
var actual = new Set([{x: 1}, {x: 1}]),
|
||||
expected = new Set([{x: 1}, {x: 2}]),
|
||||
message = 'Expected Set( Object({ x: 1 }), Object({ x: 1 }) ) to equal Set( Object({ x: 1 }), Object({ x: 2 }) ).';
|
||||
var actual = new Set();
|
||||
actual.add({x: 1});
|
||||
actual.add({x: 1});
|
||||
var expected = new Set();
|
||||
expected.add({x: 1});
|
||||
expected.add({x: 2});
|
||||
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 1 }) ) to equal Set( Object({ x: 1 }), Object({ x: 2 }) ).';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -407,9 +423,13 @@ describe("toEqual", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
// Use 'duplicate' object in expected so sizes match
|
||||
var actual = new Set([{x: 1}, {x: 2}]),
|
||||
expected = new Set([{x: 1}, {x: 1}]),
|
||||
message = 'Expected Set( Object({ x: 1 }), Object({ x: 2 }) ) to equal Set( Object({ x: 1 }), Object({ x: 1 }) ).';
|
||||
var actual = new Set();
|
||||
actual.add({x: 1});
|
||||
actual.add({x: 2});
|
||||
var expected = new Set();
|
||||
expected.add({x: 1});
|
||||
expected.add({x: 1});
|
||||
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 2 }) ) to equal Set( Object({ x: 1 }), Object({ x: 1 }) ).';
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -417,11 +437,13 @@ describe("toEqual", function() {
|
||||
// == Maps ==
|
||||
|
||||
it("does not report mismatches between deep equal Maps", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
// values are the same but with different object identity
|
||||
var actual = new Map([['a', {x: 1}]]),
|
||||
expected = new Map([['a', {x: 1}]]);
|
||||
var actual = new Map();
|
||||
actual.set('a',{x:1});
|
||||
var expected = new Map();
|
||||
expected.set('a',{x:1});
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||
});
|
||||
@@ -429,9 +451,11 @@ describe("toEqual", function() {
|
||||
it("reports deep mismatches within Maps", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = new Map([['a', {x: 1}]]),
|
||||
expected = new Map([['a', {x: 2}]]),
|
||||
message = "Expected Map( [ 'a', Object({ x: 1 }) ] ) to equal Map( [ 'a', Object({ x: 2 }) ] ).";
|
||||
var actual = new Map();
|
||||
actual.set('a',{x:1});
|
||||
var expected = new Map();
|
||||
expected.set('a',{x:2});
|
||||
var message = "Expected Map( [ 'a', Object({ x: 1 }) ] ) to equal Map( [ 'a', Object({ x: 2 }) ] ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -439,9 +463,12 @@ describe("toEqual", function() {
|
||||
it("reports mismatches between Maps nested in objects", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = {Maps: [new Map([['a', 1]])]},
|
||||
expected = {Maps: [new Map([['a', 2]])]},
|
||||
message = "Expected $.Maps[0] = Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ] ).";
|
||||
var actual = {Maps:[new Map()]};
|
||||
actual.Maps[0].set('a',1);
|
||||
var expected = {Maps:[new Map()]};
|
||||
expected.Maps[0].set('a',2);
|
||||
|
||||
var message = "Expected $.Maps[0] = Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ] ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -449,9 +476,12 @@ describe("toEqual", function() {
|
||||
it("reports mismatches between Maps of different lengths", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = new Map([['a', 1]]),
|
||||
expected = new Map([['a', 2], ['b', 1]]),
|
||||
message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ], [ 'b', 1 ] ).";
|
||||
var actual = new Map();
|
||||
actual.set('a',1);
|
||||
var expected = new Map();
|
||||
expected.set('a',2);
|
||||
expected.set('b',1);
|
||||
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ], [ 'b', 1 ] ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -459,18 +489,22 @@ describe("toEqual", function() {
|
||||
it("reports mismatches between Maps with equal values but differing keys", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = new Map([['a', 1]]),
|
||||
expected = new Map([['b', 1]]),
|
||||
message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'b', 1 ] ).";
|
||||
var actual = new Map();
|
||||
actual.set('a',1);
|
||||
var expected = new Map();
|
||||
expected.set('b',1);
|
||||
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'b', 1 ] ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("does not report mismatches between Maps with keys with same object identity", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var key = {x: 1},
|
||||
actual = new Map([[key, 2]]),
|
||||
expected = new Map([[key, 2]]);
|
||||
var key = {x: 1};
|
||||
var actual = new Map();
|
||||
actual.set(key,2);
|
||||
var expected = new Map();
|
||||
expected.set(key,2);
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||
});
|
||||
@@ -478,9 +512,11 @@ describe("toEqual", function() {
|
||||
it("reports mismatches between Maps with identical keys with different object identity", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = new Map([[{x: 1}, 2]]),
|
||||
expected = new Map([[{x: 1}, 2]]),
|
||||
message = "Expected Map( [ Object({ x: 1 }), 2 ] ) to equal Map( [ Object({ x: 1 }), 2 ] ).";
|
||||
var actual = new Map();
|
||||
actual.set({x:1},2);
|
||||
var expected = new Map();
|
||||
expected.set({x:1},2);
|
||||
var message = "Expected Map( [ Object({ x: 1 }), 2 ] ) to equal Map( [ Object({ x: 1 }), 2 ] ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
@@ -488,8 +524,11 @@ describe("toEqual", function() {
|
||||
it("does not report mismatches when comparing Map key to jasmine.anything()", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var actual = new Map([['a', 1]]),
|
||||
expected = new Map([[jasmineUnderTest.anything(), 1]]);
|
||||
var actual = new Map();
|
||||
actual.set('a',1);
|
||||
var expected = new Map();
|
||||
expected.set(jasmineUnderTest.anything(),1);
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||
});
|
||||
|
||||
@@ -497,9 +536,12 @@ describe("toEqual", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
|
||||
var key = Symbol(),
|
||||
actual = new Map([[key, 1]]),
|
||||
expected = new Map([[key, 1]]);
|
||||
var key = Symbol();
|
||||
var actual = new Map();
|
||||
actual.set(key,1);
|
||||
var expected = new Map();
|
||||
expected.set(key,1);
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||
});
|
||||
|
||||
@@ -507,9 +549,11 @@ describe("toEqual", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
|
||||
var actual = new Map([[Symbol(), 1]]),
|
||||
expected = new Map([[Symbol(), 1]]),
|
||||
message = "Expected Map( [ Symbol(), 1 ] ) to equal Map( [ Symbol(), 1 ] ).";
|
||||
var actual = new Map();
|
||||
actual.set(Symbol(),1);
|
||||
var expected = new Map();
|
||||
expected.set(Symbol(),1);
|
||||
var message = "Expected Map( [ Symbol(), 1 ] ) to equal Map( [ Symbol(), 1 ] ).";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toBe(message);
|
||||
});
|
||||
@@ -518,8 +562,11 @@ describe("toEqual", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
|
||||
var actual = new Map([[Symbol(), 1]]),
|
||||
expected = new Map([[jasmineUnderTest.anything(), 1]]);
|
||||
var actual = new Map();
|
||||
actual.set(Symbol(),1);
|
||||
var expected = new Map();
|
||||
expected.set(jasmineUnderTest.anything(),1);
|
||||
|
||||
expect(compareEquals(actual, expected).pass).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -3,10 +3,25 @@
|
||||
if (typeof Map === 'undefined') { return false; }
|
||||
|
||||
try {
|
||||
var s = new Map([['a', 4]]);
|
||||
if (s.size !== 1) { return false; }
|
||||
if (s.keys().next().value !== 'a') { return false; }
|
||||
if (s.values().next().value !== 4) { return false; }
|
||||
var s = new Map();
|
||||
s.set('a',1);
|
||||
s.set('b',2);
|
||||
|
||||
if (s.size !== 2) { return false; }
|
||||
if (s.has('a') !== true) { return false; }
|
||||
|
||||
var iterations = 0;
|
||||
var ifForEachWorking = true;
|
||||
s.forEach(function(value, key, map) {
|
||||
ifForEachWorking = ifForEachWorking && map === s;
|
||||
if (key==='a') {
|
||||
ifForEachWorking = ifForEachWorking && value===1;
|
||||
}
|
||||
iterations++;
|
||||
});
|
||||
if (iterations !== 2) { return false; }
|
||||
if (ifForEachWorking !== true) { return false; }
|
||||
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
|
||||
@@ -3,9 +3,29 @@
|
||||
if (typeof Set === 'undefined') { return false; }
|
||||
|
||||
try {
|
||||
var s = new Set([4]);
|
||||
if (s.size !== 1) { return false; }
|
||||
if (s.values().next().value !== 4) { return false; }
|
||||
var s = new Set();
|
||||
s.add(1);
|
||||
s.add(2);
|
||||
|
||||
if (s.size !== 2) { return false; }
|
||||
if (s.has(1) !== true) { return false; }
|
||||
|
||||
var iterations = 0;
|
||||
var isForEachWorking = true;
|
||||
s.forEach(function(value, key, set) {
|
||||
isForEachWorking = isForEachWorking && set === s;
|
||||
|
||||
if (iterations===0) {
|
||||
isForEachWorking = isForEachWorking && (key===value) && value===1;
|
||||
} else if (iterations===1) {
|
||||
isForEachWorking = isForEachWorking && (key===value) && value===2;
|
||||
}
|
||||
|
||||
iterations++;
|
||||
});
|
||||
if (iterations !== 2) { return false; }
|
||||
if (isForEachWorking !== true) { return false; }
|
||||
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
|
||||
@@ -124,6 +124,7 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
|
||||
}
|
||||
|
||||
do {
|
||||
deletedKeys = [];
|
||||
var newCurrentTime = scheduledLookup.shift();
|
||||
tickDate(newCurrentTime - currentTime);
|
||||
|
||||
|
||||
@@ -40,9 +40,9 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
this.emitScalar('HTMLNode');
|
||||
} else if (value instanceof Date) {
|
||||
this.emitScalar('Date(' + value + ')');
|
||||
} else if (j$.getType_(value) == '[object Set]') {
|
||||
} else if (j$.isSet(value)) {
|
||||
this.emitSet(value);
|
||||
} else if (j$.getType_(value) == '[object Map]') {
|
||||
} else if (j$.isMap(value)) {
|
||||
this.emitMap(value);
|
||||
} else if (j$.isTypedArray_(value)) {
|
||||
this.emitTypedArray(value);
|
||||
@@ -139,13 +139,18 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
}
|
||||
this.append('Set( ');
|
||||
var size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||
var iter = set.values();
|
||||
for (var i = 0; i < size; i++) {
|
||||
var i = 0;
|
||||
set.forEach( function( value, key ) {
|
||||
if (i >= size) {
|
||||
return;
|
||||
}
|
||||
if (i > 0) {
|
||||
this.append(', ');
|
||||
}
|
||||
this.format(iter.next().value);
|
||||
}
|
||||
this.format(value);
|
||||
|
||||
i++;
|
||||
}, this );
|
||||
if (set.size > size){
|
||||
this.append(', ...');
|
||||
}
|
||||
@@ -159,13 +164,18 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
}
|
||||
this.append('Map( ');
|
||||
var size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||
var iter = map.entries();
|
||||
for (var i = 0; i < size; i++) {
|
||||
var i = 0;
|
||||
map.forEach( function( value, key ) {
|
||||
if (i >= size) {
|
||||
return;
|
||||
}
|
||||
if (i > 0) {
|
||||
this.append(', ');
|
||||
}
|
||||
this.format(iter.next().value);
|
||||
}
|
||||
this.format([key,value]);
|
||||
|
||||
i++;
|
||||
}, this );
|
||||
if (map.size > size){
|
||||
this.append(', ...');
|
||||
}
|
||||
|
||||
@@ -104,6 +104,14 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
return obj.nodeType > 0;
|
||||
};
|
||||
|
||||
j$.isMap = function(obj) {
|
||||
return typeof jasmineGlobal.Map !== 'undefined' && obj.constructor === jasmineGlobal.Map;
|
||||
};
|
||||
|
||||
j$.isSet = function(obj) {
|
||||
return typeof jasmineGlobal.Set !== 'undefined' && obj.constructor === jasmineGlobal.Set;
|
||||
};
|
||||
|
||||
j$.isPromise = function(obj) {
|
||||
return typeof jasmineGlobal.Promise !== 'undefined' && obj.constructor === jasmineGlobal.Promise;
|
||||
};
|
||||
|
||||
@@ -192,7 +192,7 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
diffBuilder.record(a, b);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
var aIsPromise = j$.isPromise(a);
|
||||
var bIsPromise = j$.isPromise(b);
|
||||
if (aIsPromise && bIsPromise) {
|
||||
@@ -232,26 +232,34 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
} else if (className == '[object Map]') {
|
||||
} else if (j$.isMap(a) && j$.isMap(b)) {
|
||||
if (a.size != b.size) {
|
||||
diffBuilder.record(a, b);
|
||||
return false;
|
||||
}
|
||||
|
||||
var keysA = [];
|
||||
var keysB = [];
|
||||
a.forEach( function( valueA, keyA ) {
|
||||
keysA.push( keyA );
|
||||
});
|
||||
b.forEach( function( valueB, keyB ) {
|
||||
keysB.push( keyB );
|
||||
});
|
||||
|
||||
// For both sets of keys, check they map to equal values in both maps.
|
||||
// Keep track of corresponding keys (in insertion order) in order to handle asymmetric obj keys.
|
||||
var mapKeys = [a.keys(), b.keys()];
|
||||
var cmpKeys = [b.keys(), a.keys()];
|
||||
var mapIter, mapKeyIt, mapKey, mapValueA, mapValueB;
|
||||
var cmpIter, cmpKeyIt, cmpKey;
|
||||
var mapKeys = [keysA, keysB];
|
||||
var cmpKeys = [keysB, keysA];
|
||||
var mapIter, mapKey, mapValueA, mapValueB;
|
||||
var cmpIter, cmpKey;
|
||||
for (i = 0; result && i < mapKeys.length; i++) {
|
||||
mapIter = mapKeys[i];
|
||||
cmpIter = cmpKeys[i];
|
||||
mapKeyIt = mapIter.next();
|
||||
cmpKeyIt = cmpIter.next();
|
||||
while (result && !mapKeyIt.done) {
|
||||
mapKey = mapKeyIt.value;
|
||||
cmpKey = cmpKeyIt.value;
|
||||
|
||||
for (var j = 0; result && j < mapIter.length; j++) {
|
||||
mapKey = mapIter[j];
|
||||
cmpKey = cmpIter[j];
|
||||
mapValueA = a.get(mapKey);
|
||||
|
||||
// Only use the cmpKey when one of the keys is asymmetric and the corresponding key matches,
|
||||
@@ -264,8 +272,6 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
mapValueB = b.get(mapKey);
|
||||
}
|
||||
result = eq(mapValueA, mapValueB, aStack, bStack, customTesters, j$.NullDiffBuilder());
|
||||
mapKeyIt = mapIter.next();
|
||||
cmpKeyIt = cmpIter.next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,48 +279,49 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
||||
diffBuilder.record(a, b);
|
||||
return false;
|
||||
}
|
||||
} else if (className == '[object Set]') {
|
||||
} else if (j$.isSet(a) && j$.isSet(b)) {
|
||||
if (a.size != b.size) {
|
||||
diffBuilder.record(a, b);
|
||||
return false;
|
||||
}
|
||||
|
||||
var valuesA = [];
|
||||
a.forEach( function( valueA ) {
|
||||
valuesA.push( valueA );
|
||||
});
|
||||
var valuesB = [];
|
||||
b.forEach( function( valueB ) {
|
||||
valuesB.push( valueB );
|
||||
});
|
||||
|
||||
// For both sets, check they are all contained in the other set
|
||||
var setPairs = [[a, b], [b, a]];
|
||||
var setPairs = [[valuesA, valuesB], [valuesB, valuesA]];
|
||||
var stackPairs = [[aStack, bStack], [bStack, aStack]];
|
||||
var baseIter, baseValueIt, baseValue, baseStack;
|
||||
var otherSet, otherIter, otherValueIt, otherValue, otherStack;
|
||||
var baseValues, baseValue, baseStack;
|
||||
var otherValues, otherValue, otherStack;
|
||||
var found;
|
||||
var prevStackSize;
|
||||
for (i = 0; result && i < setPairs.length; i++) {
|
||||
baseIter = setPairs[i][0].values();
|
||||
otherSet = setPairs[i][1];
|
||||
baseValues = setPairs[i][0];
|
||||
otherValues = setPairs[i][1];
|
||||
baseStack = stackPairs[i][0];
|
||||
otherStack = stackPairs[i][1];
|
||||
// For each value in the base set...
|
||||
baseValueIt = baseIter.next();
|
||||
while (result && !baseValueIt.done) {
|
||||
baseValue = baseValueIt.value;
|
||||
for (var k = 0; result && k < baseValues.length; k++) {
|
||||
baseValue = baseValues[k];
|
||||
found = false;
|
||||
// ... test that it is present in the other set
|
||||
// Optimisation: start looking for value by object identity
|
||||
found = otherSet.has(baseValue);
|
||||
if (!found) {
|
||||
otherIter = otherSet.values();
|
||||
otherValueIt = otherIter.next();
|
||||
}
|
||||
// If not found, compare by value equality
|
||||
while (!found && !otherValueIt.done) {
|
||||
otherValue = otherValueIt.value;
|
||||
for (var l = 0; !found && l < otherValues.length; l++) {
|
||||
otherValue = otherValues[l];
|
||||
prevStackSize = baseStack.length;
|
||||
// compare by value equality
|
||||
found = eq(baseValue, otherValue, baseStack, otherStack, customTesters, j$.NullDiffBuilder());
|
||||
if (!found && prevStackSize !== baseStack.length) {
|
||||
baseStack.splice(prevStackSize);
|
||||
otherStack.splice(prevStackSize);
|
||||
}
|
||||
otherValueIt = otherIter.next();
|
||||
}
|
||||
result = result && found;
|
||||
baseValueIt = baseIter.next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user