Skip to content

Commit

Permalink
upgrade(isPromise): expose the deferred object's promise (angular#58)
Browse files Browse the repository at this point in the history
- isPromise checks to see if the input parameter has a then method
- Deferred class has a promise property and no longer has a then method
  • Loading branch information
cnishina committed Oct 28, 2016
1 parent 8870365 commit 70c9f62
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,28 @@ jasmine.Expectation.prototype.wrapCompare = function(name, matcherFactory) {

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

if (!webdriver.promise.isPromise(expectation.actual) &&
!webdriver.promise.isPromise(expected)) {
compare(expectation.actual, expected);
var actualValue = null;
var expectedValue = null;

// Check to see if the value is of type webdriver.promise.Deferred
// since deferred is not a promise.
if (expectation.actual instanceof webdriver.promise.Deferred) {
actualValue = expectation.actual.promise;
} else {
actualValue = expectation.actual;
}
if (expected instanceof webdriver.promise.Deferred) {
expectedValue = expected.promise;
} else {
expectedValue = expected;
}

if (!webdriver.promise.isPromise(actualValue) &&
!webdriver.promise.isPromise(expectedValue)) {
compare(actualValue, expectedValue);
} else {
webdriver.promise.when(expectation.actual).then(function(actual) {
return webdriver.promise.all(expected).then(function(expected) {
webdriver.promise.when(actualValue).then(function(actual) {
return webdriver.promise.all(expectedValue).then(function(expected) {
return compare(actual, expected);
});
});
Expand Down

0 comments on commit 70c9f62

Please sign in to comment.