diff --git a/spec/core/asymmetric_equality/AnySpec.js b/spec/core/asymmetric_equality/AnySpec.js index 28c433bf..44ffe6b8 100644 --- a/spec/core/asymmetric_equality/AnySpec.js +++ b/spec/core/asymmetric_equality/AnySpec.js @@ -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); diff --git a/spec/helpers/checkForSymbol.js b/spec/helpers/checkForSymbol.js new file mode 100644 index 00000000..93e414ee --- /dev/null +++ b/spec/helpers/checkForSymbol.js @@ -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()); diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json index 604af59c..a6e286df 100644 --- a/spec/support/jasmine.json +++ b/spec/support/jasmine.json @@ -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" ], diff --git a/spec/support/jasmine.yml b/spec/support/jasmine.yml index 637b00eb..eb6a784d 100644 --- a/spec/support/jasmine.yml +++ b/spec/support/jasmine.yml @@ -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: diff --git a/src/core/asymmetric_equality/Any.js b/src/core/asymmetric_equality/Any.js index c401159a..3f447529 100644 --- a/src/core/asymmetric_equality/Any.js +++ b/src/core/asymmetric_equality/Any.js @@ -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; };