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

Commit

Permalink
fix(jasminewd): support multi-argument matchers
Browse files Browse the repository at this point in the history
Implement support for multi-argument matchers in promise wrapper.

Closes #477
  • Loading branch information
konrad-garus authored and juliemr committed Jan 31, 2014
1 parent 0202576 commit de39e50
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
14 changes: 10 additions & 4 deletions jasminewd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
});
};
Expand Down
17 changes: 16 additions & 1 deletion jasminewd/spec/adapterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
};
};

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit de39e50

Please sign in to comment.