Skip to content

Commit

Permalink
Merge c391a0d into 92cc275
Browse files Browse the repository at this point in the history
  • Loading branch information
joelmukuthu committed Nov 19, 2016
2 parents 92cc275 + c391a0d commit 1a221a2
Show file tree
Hide file tree
Showing 14 changed files with 1,002 additions and 345 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
Asserts that a promise is fulfilled with a specific value:

```javascript#async:true
var promiseThatWillBeFulfilledWithAValue = expect.promise(function (resolve, reject) {
setTimeout(function () {
resolve({
foo: 'bar'
});
}, 1);
});
return expect(
promiseThatWillBeFulfilledWithAValue,
'to be fulfilled with value satisfying',
{ foo: 'bar' }
);
```

The expected value will be matched against the value with
[to satisfy](/assertions/any/to-satisfy/) semantics, so you can pass any of the
values supported by `to satisfy`:

```javascript#async:true
return expect(
expect.promise.resolve('abc'),
'to be fulfilled with value satisfying',
/b/
);
```

You get a nice diff if the assertion fails:

```javascript#async:true
return expect(
expect.promise.resolve('abc'),
'to be fulfilled with value satisfying',
'def'
);
```

```output
expected Promise (fulfilled) => 'abc' to be fulfilled with value satisfying 'def'
expected 'abc' to equal 'def'
-abc
+def
```

You can use the `exhaustively` flag to use strict
[to satisfy](/assertions/any/to-satisfy/) semantics:

```javascript#async:true
return expect(
expect.promise.resolve({
foo: 'foo',
bar: 'bar'
}),
'to be fulfilled with value exhaustively satisfying',
{
foo: 'foo'
}
);
```

```output
expected Promise (fulfilled) => { foo: 'foo', bar: 'bar' }
to be fulfilled with value exhaustively satisfying { foo: 'foo' }
expected { foo: 'foo', bar: 'bar' } to exhaustively satisfy { foo: 'foo' }
{
foo: 'foo',
bar: 'bar' // should be removed
}
```
33 changes: 33 additions & 0 deletions documentation/assertions/Promise/to-be-fulfilled-with.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Asserts that a promise is fulfilled with a specific value:

```javascript#async:true
var promiseThatWillBeFulfilledWithAValue = expect.promise(function (resolve, reject) {
setTimeout(function () {
resolve('abc');
}, 1);
});
return expect(promiseThatWillBeFulfilledWithAValue, 'to be fulfilled with', 'abc');
```

The expected value will be matched against the value with
[to satisfy](/assertions/any/to-satisfy/) semantics, so you can pass any of the
values supported by `to satisfy`:

```javascript#async:true
return expect(expect.promise.resolve('abc'), 'to be fulfilled with', /b/);
```

You get a nice diff if the assertion fails:

```javascript#async:true
return expect(expect.promise.resolve('abc'), 'to be fulfilled with', 'def');
```

```output
expected Promise (fulfilled) => 'abc' to be fulfilled with 'def'
expected 'abc' to equal 'def'
-abc
+def
```
36 changes: 0 additions & 36 deletions documentation/assertions/Promise/to-be-fulfilled.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,3 @@ return expect(rejectedPromise, 'to be fulfilled');
expected Promise (rejected) => Error('argh') to be fulfilled
Promise (rejected) => Error('argh') unexpectedly rejected with Error('argh')
```

You can assert the promise is fulfilled with a specific value by
passing a second parameter:

```javascript#async:true
var promiseThatWillBeFulfilledWithAValue = expect.promise(function (resolve, reject) {
setTimeout(function () {
resolve('abc');
}, 1);
});
return expect(promiseThatWillBeFulfilledWithAValue, 'to be fulfilled with', 'abc');
```

The expected value will be matched against the value with
[to satisfy](/assertions/any/to-satisfy/) semantics, so you can also pass a string,
a regular expression, a function, or an object:


```javascript#async:true
return expect(expect.promise.resolve('abc'), 'to be fulfilled with', /b/);
```

You get a nice diff if the assertion fails:

```javascript#async:true
return expect(expect.promise.resolve('abc'), 'to be fulfilled with', 'def');
```

```output
expected Promise (fulfilled) => 'abc' to be fulfilled with 'def'
expected 'abc' to equal 'def'
-abc
+def
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Asserts that a promise is rejected with a specific reason (error):

```javascript#async:true
var promiseThatWillBeRejectedWithAReason = expect.promise(function (resolve, reject) {
setTimeout(function () {
reject(new Error('Oh dear'));
}, 10);
});
return expect(
promiseThatWillBeRejectedWithAReason,
'to be rejected with error satisfying',
new Error('Oh dear')
);
```

The expected reason will be matched against the rejection reason with
[to satisfy](/assertions/any/to-satisfy/) semantics, so you can pass any of the
values supported by `to satisfy`:


```javascript#async:true
var promiseThatWillBeRejectedWithAReason = expect.promise(function (resolve, reject) {
setTimeout(function () {
reject(new Error('Oh dear'));
}, 10);
});
return expect(
promiseThatWillBeRejectedWithAReason,
'to be rejected with error satisfying',
/dear/
);
```

You get a nice diff if the assertion fails:

```javascript#async:true
var promiseThatWillBeRejectedWithAReason = expect.promise(function (resolve, reject) {
setTimeout(function () {
reject(new Error('Oh dear'));
}, 10);
});
return expect(
promiseThatWillBeRejectedWithAReason,
'to be rejected with error satisfying',
new Error('bugger')
);
```

```output
expected Promise (rejected) => Error('Oh dear')
to be rejected with error satisfying Error('bugger')
expected Error('Oh dear') to satisfy Error('bugger')
Error({
message: 'Oh dear' // should equal 'bugger'
//
// -Oh dear
// +bugger
})
```

You can use the `exhaustively` flag to use strict
[to satisfy](/assertions/any/to-satisfy/) semantics:

```javascript#async:true
var error = new Error('Oh dear');
error.data = { foo: 'bar' };
return expect(
expect.promise.reject(error),
'to be rejected with error exhaustively satisfying',
new Error('Oh dear')
);
```

```output
expected Promise (rejected) => Error({ message: 'Oh dear', data: { foo: 'bar' } })
to be rejected with error exhaustively satisfying Error('Oh dear')
expected Error({ message: 'Oh dear', data: { foo: 'bar' } })
to exhaustively satisfy Error('Oh dear')
Error({
message: 'Oh dear',
data: { foo: 'bar' } // should be removed
})
```
50 changes: 50 additions & 0 deletions documentation/assertions/Promise/to-be-rejected-with.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Asserts that a promise is rejected with a specific reason (error):

```javascript#async:true
var promiseThatWillBeRejectedWithAReason = expect.promise(function (resolve, reject) {
setTimeout(function () {
reject(new Error('Oh dear'));
}, 10);
});
return expect(promiseThatWillBeRejectedWithAReason, 'to be rejected with', new Error('Oh dear'));
```

The expected reason will be matched against the rejection reason with
[to satisfy](/assertions/any/to-satisfy/) semantics, so you can pass any of the
values supported by `to satisfy`:


```javascript#async:true
var promiseThatWillBeRejectedWithAReason = expect.promise(function (resolve, reject) {
setTimeout(function () {
reject(new Error('Oh dear'));
}, 10);
});
return expect(promiseThatWillBeRejectedWithAReason, 'to be rejected with', /dear/);
```

You get a nice diff if the assertion fails:

```javascript#async:true
var promiseThatWillBeRejectedWithAReason = expect.promise(function (resolve, reject) {
setTimeout(function () {
reject(new Error('Oh dear'));
}, 10);
});
return expect(promiseThatWillBeRejectedWithAReason, 'to be rejected with', new Error('bugger'));
```

```output
expected Promise (rejected) => Error('Oh dear') to be rejected with Error('bugger')
expected Error('Oh dear') to satisfy Error('bugger')
Error({
message: 'Oh dear' // should equal 'bugger'
//
// -Oh dear
// +bugger
})
```
52 changes: 0 additions & 52 deletions documentation/assertions/Promise/to-be-rejected.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,3 @@ return expect(fulfilledPromise, 'to be rejected');
expected Promise (fulfilled) to be rejected
Promise (fulfilled) unexpectedly fulfilled
```

You can assert the promise is rejected with a specific reason (error) by
passing a second parameter:

```javascript#async:true
var promiseThatWillBeRejectedWithAReason = expect.promise(function (resolve, reject) {
setTimeout(function () {
reject(new Error('Oh dear'));
}, 10);
});
return expect(promiseThatWillBeRejectedWithAReason, 'to be rejected with', new Error('Oh dear'));
```

The expected reason will be matched against the rejection reason with
[to satisfy](/assertions/any/to-satisfy/) semantics, so you can also pass a string,
a regular expression, a function, or an object:


```javascript#async:true
var promiseThatWillBeRejectedWithAReason = expect.promise(function (resolve, reject) {
setTimeout(function () {
reject(new Error('Oh dear'));
}, 10);
});
return expect(promiseThatWillBeRejectedWithAReason, 'to be rejected with', /dear/);
```

You get a nice diff if the assertion fails:

```javascript#async:true
var promiseThatWillBeRejectedWithAReason = expect.promise(function (resolve, reject) {
setTimeout(function () {
reject(new Error('Oh dear'));
}, 10);
});
return expect(promiseThatWillBeRejectedWithAReason, 'to be rejected with', new Error('bugger'));
```

```output
expected Promise (rejected) => Error('Oh dear') to be rejected with Error('bugger')
expected Error('Oh dear') to satisfy Error('bugger')
Error({
message: 'Oh dear' // should equal 'bugger'
//
// -Oh dear
// +bugger
})
```

0 comments on commit 1a221a2

Please sign in to comment.