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

Commit de39e50

Browse files
konrad-garusjuliemr
authored andcommitted
fix(jasminewd): support multi-argument matchers
Implement support for multi-argument matchers in promise wrapper. Closes #477
1 parent 0202576 commit de39e50

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

jasminewd/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,15 @@ global.afterEach = wrapInControlFlow(global.afterEach);
7171
* @param {boolean} not Whether this is being called with 'not' active.
7272
*/
7373
function wrapMatcher(matcher, actualPromise, not) {
74-
return function(expected) {
74+
return function() {
75+
var originalArgs = arguments;
7576
actualPromise.then(function(actual) {
77+
var expected = originalArgs[0];
7678
if (expected instanceof webdriver.promise.Promise) {
79+
if (originalArgs.length > 1) {
80+
throw error('Multi-argument matchers with promises are not '
81+
+ 'supported.');
82+
}
7783
expected.then(function(exp) {
7884
if (not) {
7985
expect(actual).not[matcher](exp)
@@ -82,11 +88,11 @@ function wrapMatcher(matcher, actualPromise, not) {
8288
}
8389
});
8490
} else {
91+
var expectation = expect(actual);
8592
if (not) {
86-
expect(actual).not[matcher](expected)
87-
} else {
88-
expect(actual)[matcher](expected);
93+
expectation = expectation.not;
8994
}
95+
expectation[matcher].apply(expectation, originalArgs);
9096
}
9197
});
9298
};

jasminewd/spec/adapterSpec.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ var getFakeDriver = function() {
4242
return flow.execute(function() {
4343
return webdriver.promise.fulfilled(1111);
4444
});
45-
}
45+
},
46+
getDecimalNumber: function() {
47+
return flow.execute(function() {
48+
return webdriver.promise.fulfilled(3.14159);
49+
});
50+
}
4651
};
4752
};
4853

@@ -111,6 +116,16 @@ describe('webdriverJS Jasmine adapter', function() {
111116
expect(fakeDriver.getBigNumber()).toBeLotsMoreThan(33);
112117
});
113118

119+
it('should pass multiple arguments to matcher', function() {
120+
// Passing specific precision
121+
expect(fakeDriver.getDecimalNumber()).toBeCloseTo(3.1, 1);
122+
expect(fakeDriver.getDecimalNumber()).not.toBeCloseTo(3.1, 2);
123+
124+
// Using default precision (2)
125+
expect(fakeDriver.getDecimalNumber()).not.toBeCloseTo(3.1);
126+
expect(fakeDriver.getDecimalNumber()).toBeCloseTo(3.14);
127+
});
128+
114129
describe('not', function() {
115130
it('should still pass normal synchronous tests', function() {
116131
expect(4).not.toEqual(5);

0 commit comments

Comments
 (0)