Skip to content

Commit 750898c

Browse files
committed
fix(expectation): expectations without promises no longer add to task queue
Instead, expectations without promises in either expected or actual are unchanged from the original Jasmine implementation. See angular/protractor#2894
1 parent 4717c0b commit 750898c

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ global.expect = function(actual) {
153153
return originalExpect(actual);
154154
};
155155

156+
var originalWrapCompare = jasmine.Expectation.prototype.wrapCompare;
157+
156158
/**
157159
* Creates a matcher wrapper that resolves any promises given for actual and
158160
* expected values, as well as the `pass` property of the result.
@@ -165,11 +167,16 @@ jasmine.Expectation.prototype.wrapCompare = function(name, matcherFactory) {
165167

166168
matchError.stack = matchError.stack.replace(/ +at.+jasminewd.+\n/, '');
167169

168-
webdriver.promise.when(expectation.actual).then(function(actual) {
169-
return webdriver.promise.all(expected).then(function(expected) {
170-
return compare(actual, expected);
170+
if (!webdriver.promise.isPromise(expectation.actual) &&
171+
!webdriver.promise.isPromise(expected)) {
172+
originalWrapCompare(name, matcherFactory).apply(this, arguments);
173+
} else {
174+
webdriver.promise.when(expectation.actual).then(function(actual) {
175+
return webdriver.promise.all(expected).then(function(expected) {
176+
return compare(actual, expected);
177+
});
171178
});
172-
});
179+
}
173180

174181
function compare(actual, expected) {
175182
var args = expected.slice(0);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"author": "Julie Ralph <[email protected]>",
1414
"devDependencies": {
1515
"jshint": "2.5.0",
16-
"jasmine": "2.3.2",
17-
"selenium-webdriver": "2.47.0"
16+
"jasmine": "2.4.1",
17+
"selenium-webdriver": "2.48.2"
1818
},
1919
"repository": {
2020
"type": "git",

scripts/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $CMD
99
[ "$?" -eq 0 ] || exit 1
1010
echo
1111

12-
EXPECTED_RESULTS="15 specs, 14 failures"
12+
EXPECTED_RESULTS="16 specs, 15 failures"
1313
echo "### running failing specs (expecting $EXPECTED_RESULTS)"
1414
CMD=$CMD_BASE$FAILING_SPECS
1515
echo "### $CMD"

spec/errorSpec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ describe('things that should fail', function() {
3434
done.fail('an error from done.fail');
3535
});
3636

37+
it('should error asynchronously in promise callbacks', function() {
38+
fakeDriver.sleep(50).then(function() {
39+
expect(true).toEqual(false);
40+
});
41+
});
42+
3743
it('should error asynchronously within done callback', function(done) {
3844
setTimeout(function() {
39-
expect(false).toBeTruthy();
45+
expect(false).toEqual(true);
4046
done();
4147
}, 200);
4248
});

0 commit comments

Comments
 (0)