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

Multi-argument matchers broken #477

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -110,6 +115,16 @@ describe('webdriverJS Jasmine adapter', function() {
expect(500).toBeLotsMoreThan(3);
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() {
Expand Down