-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
233 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
integration-tests/__tests__/__snapshots__/expect_async_matcher.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`works with expected non promise values and not is a failure 1`] = ` | ||
"Expected value to not have length: | ||
2 | ||
Received: | ||
1,2 | ||
received.length: | ||
2" | ||
`; | ||
|
||
exports[`works with expected non promise values is a failure 1`] = ` | ||
"Expected value to have length: | ||
2 | ||
Received: | ||
1 | ||
received.length: | ||
1" | ||
`; | ||
|
||
exports[`works with expected promise values and not is a failure 1`] = ` | ||
"Expected value to not have length: | ||
2 | ||
Received: | ||
1,2 | ||
received.length: | ||
2" | ||
`; | ||
|
||
exports[`works with expected promise values is a failure 1`] = ` | ||
"Expected value to have length: | ||
2 | ||
Received: | ||
1 | ||
received.length: | ||
1" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
async function toHaveLengthAsync( | ||
received: any, | ||
lengthPromise: Promise<number>, | ||
) { | ||
const length = await lengthPromise; | ||
|
||
const pass = received.length === length; | ||
const message = pass | ||
? () => | ||
`Expected value to not have length:\n` + | ||
` ${length}\n` + | ||
`Received:\n` + | ||
` ${received}\n` + | ||
`received.length:\n` + | ||
` ${received.length}` | ||
: () => | ||
`Expected value to have length:\n` + | ||
` ${length}\n` + | ||
`Received:\n` + | ||
` ${received}\n` + | ||
`received.length:\n` + | ||
` ${received.length}`; | ||
|
||
return {message, pass}; | ||
} | ||
|
||
expect.extend({ | ||
toHaveLengthAsync, | ||
}); | ||
|
||
it('works with expected non promise values', async () => { | ||
await (expect([1]): any).toHaveLengthAsync(Promise.resolve(1)); | ||
}); | ||
|
||
it('works with expected non promise values is a failure', async () => { | ||
try { | ||
await (expect([1]): any).toHaveLengthAsync(Promise.resolve(2)); | ||
} catch (error) { | ||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot(); | ||
} | ||
}); | ||
|
||
it('works with expected non promise values and not', async () => { | ||
await (expect([1, 2]): any).not.toHaveLengthAsync(Promise.resolve(1)); | ||
}); | ||
|
||
it('works with expected non promise values and not is a failure', async () => { | ||
try { | ||
await (expect([1, 2]): any).not.toHaveLengthAsync(Promise.resolve(2)); | ||
} catch (error) { | ||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot(); | ||
} | ||
}); | ||
|
||
it('works with expected promise values', async () => { | ||
await (expect(Promise.resolve([1])).resolves: any).toHaveLengthAsync( | ||
Promise.resolve(1), | ||
); | ||
}); | ||
|
||
it('works with expected promise values is a failure', async () => { | ||
try { | ||
await (expect(Promise.resolve([1])): any).resolves.toHaveLengthAsync( | ||
Promise.resolve(2), | ||
); | ||
} catch (error) { | ||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot(); | ||
} | ||
}); | ||
|
||
it('works with expected promise values and not', async () => { | ||
await (expect(Promise.resolve([1, 2])).resolves.not: any).toHaveLengthAsync( | ||
Promise.resolve(1), | ||
); | ||
}); | ||
|
||
it('works with expected promise values and not is a failure', async () => { | ||
try { | ||
await (expect(Promise.resolve([1, 2])).resolves.not: any).toHaveLengthAsync( | ||
Promise.resolve(2), | ||
); | ||
} catch (error) { | ||
expect(error).toBeDefined(); | ||
expect(error.message).toMatchSnapshot(); | ||
} | ||
}); |
Oops, something went wrong.