Skip to content

Commit

Permalink
Support unwrapping promises when actual is primitive and expected val…
Browse files Browse the repository at this point in the history
…ue is a promise (angular#47)
  • Loading branch information
jesseczko committed Aug 28, 2016
1 parent a8ca7e3 commit 0d52142
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,18 @@ jasmine.Expectation.prototype.wrapCompare = function(name, matcherFactory) {

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


function areAnyExpectedValuesPromises(expected){
for (var i = 0; i < expected.length; i++) {
if(webdriver.promise.isPromise(expected[i])){
return true;
}
}
return false;
}

if (!webdriver.promise.isPromise(expectation.actual) &&
!webdriver.promise.isPromise(expected)) {
!areAnyExpectedValuesPromises(expected)) {
compare(expectation.actual, expected);
} else {
webdriver.promise.when(expectation.actual).then(function(actual) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $CMD
[ "$?" -eq 0 ] || exit 1
echo

EXPECTED_RESULTS="16 specs, 15 failures"
EXPECTED_RESULTS="17 specs, 16 failures"
echo "### running failing specs (expecting $EXPECTED_RESULTS)"
CMD=$CMD_BASE$FAILING_SPECS
echo "### $CMD"
Expand Down
5 changes: 5 additions & 0 deletions spec/adapterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ describe('webdriverJS Jasmine adapter', function() {
expect(fakeDriver.getValueB()).toEqual('b');
});

it('should compare a primitive to a promise', function() {
expect('a').toEqual(fakeDriver.getValueA());
expect('b').toEqual(fakeDriver.getValueB());
});

it('beforeEach should wait for control flow', function() {
expect(beforeEachMsg).toEqual('setup done');
});
Expand Down
5 changes: 5 additions & 0 deletions spec/errorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ describe('things that should fail', function() {
expect(fakeDriver.getValueB()).toEqual('e');
});

it('should compare a primitive to a promise', function() {
expect('e').toEqual(fakeDriver.getValueA());
expect('f').toEqual(fakeDriver.getValueB());
});

it('should wait till the expect to run the flow', function() {
var promiseA = fakeDriver.getValueA();
expect(promiseA.isPending()).toBe(true);
Expand Down

0 comments on commit 0d52142

Please sign in to comment.