Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix(jasminewd): patched matcher should understand 'not'
Browse files Browse the repository at this point in the history
Closes #139.
  • Loading branch information
juliemr committed Nov 12, 2013
1 parent c7bcc20 commit 137d804
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
20 changes: 15 additions & 5 deletions jasminewd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
};
Expand All @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions jasminewd/spec/adapterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 137d804

Please sign in to comment.