From 137d8040778215fd841654d3ca465b71f8719ea5 Mon Sep 17 00:00:00 2001 From: Julie Date: Mon, 11 Nov 2013 18:18:26 -0800 Subject: [PATCH] fix(jasminewd): patched matcher should understand 'not' Closes #139. --- jasminewd/index.js | 20 +++++++++++++++----- jasminewd/spec/adapterSpec.js | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/jasminewd/index.js b/jasminewd/index.js index 31afdedd0..42be6d7c2 100644 --- a/jasminewd/index.js +++ b/jasminewd/index.js @@ -67,16 +67,25 @@ global.afterEach = wrapInControlFlow(global.afterEach); * @param {!Function} matcher The matcher function to wrap. * @param {webdriver.promise.Promise} actualPromise The promise which will * resolve to the actual value being tested. + * @param {boolean} not Whether this is being called with 'not' active. */ -function wrapMatcher(matcher, actualPromise) { +function wrapMatcher(matcher, actualPromise, not) { return function(expected) { actualPromise.then(function(actual) { if (expected instanceof webdriver.promise.Promise) { expected.then(function(exp) { - expect(actual)[matcher](exp); + if (not) { + expect(actual).not[matcher](exp) + } else { + expect(actual)[matcher](exp); + } }); } else { - expect(actual)[matcher](expected); + if (not) { + expect(actual).not[matcher](expected) + } else { + expect(actual)[matcher](expected); + } } }); }; @@ -89,12 +98,13 @@ function wrapMatcher(matcher, actualPromise) { * resolve to the acutal value being tested. */ function promiseMatchers(actualPromise) { - var promises = {}; + var promises = {not: {}}; var env = jasmine.getEnv(); var matchersClass = env.currentSpec.matchersClass || env.matchersClass; for (matcher in matchersClass.prototype) { - promises[matcher] = wrapMatcher(matcher, actualPromise); + promises[matcher] = wrapMatcher(matcher, actualPromise, false); + promises.not[matcher] = wrapMatcher(matcher, actualPromise, true); }; return promises; diff --git a/jasminewd/spec/adapterSpec.js b/jasminewd/spec/adapterSpec.js index 71f09d62f..25315831d 100644 --- a/jasminewd/spec/adapterSpec.js +++ b/jasminewd/spec/adapterSpec.js @@ -111,6 +111,20 @@ describe('webdriverJS Jasmine adapter', function() { expect(fakeDriver.getBigNumber()).toBeLotsMoreThan(33); }); + describe('not', function() { + it('should still pass normal synchronous tests', function() { + expect(4).not.toEqual(5); + }); + + it('should compare a promise to a primitive', function() { + expect(fakeDriver.getValueA()).not.toEqual('b'); + }); + + it('should compare a promise to a promise', function() { + expect(fakeDriver.getValueA()).not.toEqual(fakeDriver.getValueB()); + }); + }); + it('should throw an error with a WebElement actual value', function() { var webElement = new webdriver.WebElement(fakeDriver, 'idstring');