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

Commit 6223825

Browse files
Jeremy Moronyjuliemr
Jeremy Morony
authored andcommitted
fix(jasminewd): allow use of custom matchers
Using jasmine.Matchers.prototype to generate the chained methods for expect() calls is flawed because it does not pick up custom matchers defined using addMatcher. Instead, use either the matchersClass for the current spec or from the environment.
1 parent c22fc38 commit 6223825

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

jasminewd/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ function wrapMatcher(matcher, actualPromise) {
9090
*/
9191
function promiseMatchers(actualPromise) {
9292
var promises = {};
93-
for (matcher in jasmine.Matchers.prototype) {
93+
var env = jasmine.getEnv();
94+
var matchersClass = env.currentSpec.matchersClass || env.matchersClass;
95+
96+
for (matcher in matchersClass.prototype) {
9497
promises[matcher] = wrapMatcher(matcher, actualPromise);
9598
};
9699

jasminewd/spec/adapterSpec.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ var getFakeDriver = function() {
3434
return flow.execute(function() {
3535
return webdriver.promise.fulfilled('b');
3636
});
37+
},
38+
getBigNumber: function() {
39+
return flow.execute(function() {
40+
return webdriver.promise.fulfilled(1111);
41+
});
3742
}
3843
};
3944
};
@@ -96,7 +101,13 @@ describe('webdriverJS Jasmine adapter', function() {
96101
it('should allow scheduling of tasks', function() {
97102
fakeDriver.sleep(300);
98103
expect(fakeDriver.getValueB()).toEqual('b');
99-
})
104+
});
105+
106+
it('should allow the use of custom matchers', function() {
107+
expect(500).toBeLotsMoreThan(3);
108+
expect(fakeDriver.getBigNumber()).toBeLotsMoreThan(33);
109+
});
110+
100111

101112
// Uncomment to see timeout failures.
102113
// it('should timeout after 200ms', function() {

0 commit comments

Comments
 (0)