From bad9c63bf72fd32d6fb816185276036dc8aed6bd Mon Sep 17 00:00:00 2001 From: Gregg Van Hove Date: Tue, 27 Sep 2016 15:36:01 -0700 Subject: [PATCH] Properly skip Set tests in browsers that don't really support it --- spec/core/PrettyPrintSpec.js | 4 ++-- spec/core/matchers/matchersUtilSpec.js | 11 +++++------ spec/helpers/BrowserFlags.js | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/spec/core/PrettyPrintSpec.js b/spec/core/PrettyPrintSpec.js index 415839b0..301ba80e 100644 --- a/spec/core/PrettyPrintSpec.js +++ b/spec/core/PrettyPrintSpec.js @@ -15,13 +15,13 @@ describe("jasmineUnderTest.pp", function () { }); describe('stringify sets', function() { - if (typeof Set === 'undefined') { return; } - it("should stringify sets properly", function() { + jasmine.getEnv().requireFunctioningSets(); expect(jasmineUnderTest.pp(new Set([1, 2]))).toEqual("Set( 1, 2 )"); }); it("should truncate sets with more elments than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH", function() { + jasmine.getEnv().requireFunctioningSets(); var originalMaxSize = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH; try { diff --git a/spec/core/matchers/matchersUtilSpec.js b/spec/core/matchers/matchersUtilSpec.js index 950c3427..d5c9c200 100644 --- a/spec/core/matchers/matchersUtilSpec.js +++ b/spec/core/matchers/matchersUtilSpec.js @@ -369,12 +369,12 @@ describe("matchersUtil", function() { }); it("passes when comparing two empty sets", function() { - if (typeof Set === 'undefined') { return; } + jasmine.getEnv().requireFunctioningSets(); expect(jasmineUnderTest.matchersUtil.equals(new Set(), new Set())).toBe(true); }); it("passes when comparing identical sets", function() { - if (typeof Set === 'undefined') { return; } + jasmine.getEnv().requireFunctioningSets(); var setA = new Set([6, 5]); var setB = new Set(); setB.add(6); @@ -383,26 +383,25 @@ describe("matchersUtil", function() { }); it("fails for sets with different elements", function() { - if (typeof Set === 'undefined') { return; } + jasmine.getEnv().requireFunctioningSets(); var setA = new Set([6, 3, 5]); var setB = new Set([6, 4, 5]); expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false); }); it("fails for sets of different size", function() { - if (typeof Set === 'undefined') { return; } + jasmine.getEnv().requireFunctioningSets(); var setA = new Set([6, 3]); var setB = new Set([6, 4, 5]); expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false); }); it("fails for sets with different insertion order", function() { - if (typeof Set === 'undefined') { return; } + jasmine.getEnv().requireFunctioningSets(); var setA = new Set([3, 6]); var setB = new Set([6, 3]); expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false); }); - }); describe("contains", function() { diff --git a/spec/helpers/BrowserFlags.js b/spec/helpers/BrowserFlags.js index c8300b62..ef8d607f 100644 --- a/spec/helpers/BrowserFlags.js +++ b/spec/helpers/BrowserFlags.js @@ -20,4 +20,23 @@ return /Firefox\/([0-9]{0,})/.exec(userAgent); }); + function hasFunctioningSets() { + 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; } + return true; + } catch(e) { + return false; + } + } + + env.requireFunctioningSets = function() { + if (!hasFunctioningSets()) { + pending("Browser has incomplete or missing support for Sets"); + } + }; + })(jasmine.getEnv());