Skip to content

Commit

Permalink
Merge branch 'fix/willBe_description'
Browse files Browse the repository at this point in the history
  • Loading branch information
rluba committed Jan 20, 2015
2 parents ddd30a8 + c700a96 commit 53a1915
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dist/hamjest-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,13 +1133,13 @@ function IsFulfilled(valueOrMatcher) {
.append('was not fulfilled (')
.appendValue(qPromise.inspect())
.append(')');
deferred.resolve();
}
else {
description
.append('fulfillment value: ');
valueMatcher.describeMismatch(qPromise.inspect().value, description);
deferred.resolve(valueMatcher.describeMismatch(qPromise.inspect().value, description));
}
deferred.resolve();
});
return deferred.promise;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/hamjest-deps.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/hamjest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,13 +1133,13 @@ function IsFulfilled(valueOrMatcher) {
.append('was not fulfilled (')
.appendValue(qPromise.inspect())
.append(')');
deferred.resolve();
}
else {
description
.append('fulfillment value: ');
valueMatcher.describeMismatch(qPromise.inspect().value, description);
deferred.resolve(valueMatcher.describeMismatch(qPromise.inspect().value, description));
}
deferred.resolve();
});
return deferred.promise;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/hamjest.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/matchers/IsFulfilled.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ function IsFulfilled(valueOrMatcher) {
.append('was not fulfilled (')
.appendValue(qPromise.inspect())
.append(')');
deferred.resolve();
}
else {
description
.append('fulfillment value: ');
valueMatcher.describeMismatch(qPromise.inspect().value, description);
deferred.resolve(valueMatcher.describeMismatch(qPromise.inspect().value, description));
}
deferred.resolve();
});
return deferred.promise;
}
Expand Down
66 changes: 66 additions & 0 deletions test/matchers/IsFulfilledSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,71 @@ describe('IsFulfilled', function () {
});
});
});

describe('with a promising matcher', function () {
var sut;
beforeEach(function () {
sut = fulfilled(__.contains(__.willBe('expected')));
});

it('should match fulfilled promise with matching values', function (done) {
var aFulfilledPromise = q([
q('expected')
]);

sut.matches(aFulfilledPromise).done(function (value) {
assertTrue(value);
done();
});
});

it('should not match fulfilled promise with nonmatching value', function (done) {
var aFulfilledPromise = q([
q('another value')
]);

sut.matches(aFulfilledPromise).done(function (value) {
assertFalse(value);
done();
});
});

it('should wait for pending promises', function (done) {
var deferred = q.defer();
var aFulfilledPromiseContainingAPendingPromise = q([deferred.promise]);

sut.matches(aFulfilledPromiseContainingAPendingPromise).done(function (value) {
assertTrue(value);
done();
});

deferred.resolve('expected');
});

describe('description', function () {
var description;

beforeEach(function () {
description = new Description();
});

it('should contain matcher description', function () {

sut.describeTo(description);

__.assertThat(description.get(), __.equalTo('a promise fulfilled with [a promise fulfilled with "expected"]'));
});

it('should contain mismatch description', function (done) {

var actual = q([q('another value')]);

sut.describeMismatch(actual, description).done(function () {
__.assertThat(description.get(), __.equalTo('fulfillment value: item 0: fulfillment value: was "another value"\n'));
done();
});
});
});
});
});
});

0 comments on commit 53a1915

Please sign in to comment.