From de39e5077d09daaeb885767e968a5cef78c9cac7 Mon Sep 17 00:00:00 2001 From: konradgarus Date: Thu, 30 Jan 2014 10:20:02 +0100 Subject: [PATCH] fix(jasminewd): support multi-argument matchers Implement support for multi-argument matchers in promise wrapper. Closes #477 --- jasminewd/index.js | 14 ++++++++++---- jasminewd/spec/adapterSpec.js | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/jasminewd/index.js b/jasminewd/index.js index a029e6c7e..4a656ca85 100644 --- a/jasminewd/index.js +++ b/jasminewd/index.js @@ -71,9 +71,15 @@ global.afterEach = wrapInControlFlow(global.afterEach); * @param {boolean} not Whether this is being called with 'not' active. */ function wrapMatcher(matcher, actualPromise, not) { - return function(expected) { + return function() { + var originalArgs = arguments; actualPromise.then(function(actual) { + var expected = originalArgs[0]; if (expected instanceof webdriver.promise.Promise) { + if (originalArgs.length > 1) { + throw error('Multi-argument matchers with promises are not ' + + 'supported.'); + } expected.then(function(exp) { if (not) { expect(actual).not[matcher](exp) @@ -82,11 +88,11 @@ function wrapMatcher(matcher, actualPromise, not) { } }); } else { + var expectation = expect(actual); if (not) { - expect(actual).not[matcher](expected) - } else { - expect(actual)[matcher](expected); + expectation = expectation.not; } + expectation[matcher].apply(expectation, originalArgs); } }); }; diff --git a/jasminewd/spec/adapterSpec.js b/jasminewd/spec/adapterSpec.js index 25315831d..7f6b04550 100644 --- a/jasminewd/spec/adapterSpec.js +++ b/jasminewd/spec/adapterSpec.js @@ -42,7 +42,12 @@ var getFakeDriver = function() { return flow.execute(function() { return webdriver.promise.fulfilled(1111); }); - } + }, + getDecimalNumber: function() { + return flow.execute(function() { + return webdriver.promise.fulfilled(3.14159); + }); + } }; }; @@ -111,6 +116,16 @@ describe('webdriverJS Jasmine adapter', function() { expect(fakeDriver.getBigNumber()).toBeLotsMoreThan(33); }); + it('should pass multiple arguments to matcher', function() { + // Passing specific precision + expect(fakeDriver.getDecimalNumber()).toBeCloseTo(3.1, 1); + expect(fakeDriver.getDecimalNumber()).not.toBeCloseTo(3.1, 2); + + // Using default precision (2) + expect(fakeDriver.getDecimalNumber()).not.toBeCloseTo(3.1); + expect(fakeDriver.getDecimalNumber()).toBeCloseTo(3.14); + }); + describe('not', function() { it('should still pass normal synchronous tests', function() { expect(4).not.toEqual(5);