Merge branch 'anysymbol-fix' of https://github.com/voithos/jasmine
- Merge #1435 from @voithos
This commit is contained in:
@@ -1499,6 +1499,12 @@ getJasmineRequireObj().Any = function(j$) {
|
||||
return typeof other == 'boolean';
|
||||
}
|
||||
|
||||
/* jshint -W122 */
|
||||
if (typeof Symbol != 'undefined' && this.expectedObject == Symbol) {
|
||||
return typeof other == 'symbol';
|
||||
}
|
||||
/* jshint +W122 */
|
||||
|
||||
return other instanceof this.expectedObject;
|
||||
};
|
||||
|
||||
|
||||
@@ -29,6 +29,38 @@ describe("Any", function() {
|
||||
expect(any.asymmetricMatch(true)).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Map", function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
|
||||
var any = new jasmineUnderTest.Any(Map);
|
||||
|
||||
expect(any.asymmetricMatch(new Map())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Set", function() {
|
||||
jasmine.getEnv().requireFunctioningSets();
|
||||
|
||||
var any = new jasmineUnderTest.Any(Set);
|
||||
|
||||
expect(any.asymmetricMatch(new Set())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a TypedArray", function() {
|
||||
jasmine.getEnv().requireFunctioningTypedArrays();
|
||||
|
||||
var any = new jasmineUnderTest.Any(Uint32Array);
|
||||
|
||||
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a Symbol", function() {
|
||||
jasmine.getEnv().requireFunctioningSymbols();
|
||||
|
||||
var any = new jasmineUnderTest.Any(Symbol);
|
||||
|
||||
expect(any.asymmetricMatch(Symbol())).toBe(true);
|
||||
});
|
||||
|
||||
it("matches another constructed object", function() {
|
||||
var Thing = function() {},
|
||||
any = new jasmineUnderTest.Any(Thing);
|
||||
|
||||
28
spec/helpers/checkForSymbol.js
Normal file
28
spec/helpers/checkForSymbol.js
Normal file
@@ -0,0 +1,28 @@
|
||||
(function(env) {
|
||||
function hasFunctioningSymbols() {
|
||||
if (typeof Symbol === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
var s1 = Symbol();
|
||||
var s2 = Symbol();
|
||||
if (typeof s1 !== 'symbol') {
|
||||
return false;
|
||||
}
|
||||
if (s1 === s2) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
env.requireFunctioningSymbols = function() {
|
||||
if (!hasFunctioningSymbols()) {
|
||||
env.pending("Browser has incomplete or missing support for Symbols");
|
||||
}
|
||||
};
|
||||
|
||||
})(jasmine.getEnv());
|
||||
@@ -7,8 +7,9 @@
|
||||
],
|
||||
"helpers": [
|
||||
"helpers/asyncAwait.js",
|
||||
"helpers/checkForSet.js",
|
||||
"helpers/checkForMap.js",
|
||||
"helpers/checkForSet.js",
|
||||
"helpers/checkForSymbol.js",
|
||||
"helpers/checkForTypedArrays.js",
|
||||
"helpers/nodeDefineJasmineUnderTest.js"
|
||||
],
|
||||
|
||||
@@ -18,8 +18,9 @@ stylesheets:
|
||||
helpers:
|
||||
- 'helpers/asyncAwait.js'
|
||||
- 'helpers/BrowserFlags.js'
|
||||
- 'helpers/checkForSet.js'
|
||||
- 'helpers/checkForMap.js'
|
||||
- 'helpers/checkForSet.js'
|
||||
- 'helpers/checkForSymbol.js'
|
||||
- 'helpers/checkForTypedArrays.js'
|
||||
- 'helpers/defineJasmineUnderTest.js'
|
||||
spec_files:
|
||||
|
||||
@@ -31,6 +31,12 @@ getJasmineRequireObj().Any = function(j$) {
|
||||
return typeof other == 'boolean';
|
||||
}
|
||||
|
||||
/* jshint -W122 */
|
||||
if (typeof Symbol != 'undefined' && this.expectedObject == Symbol) {
|
||||
return typeof other == 'symbol';
|
||||
}
|
||||
/* jshint +W122 */
|
||||
|
||||
return other instanceof this.expectedObject;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user