-
-
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
6 changed files
with
151 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* 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 and not', async () => { | ||
await (expect([1, 2]).not: any).toHaveLengthAsync(Promise.resolve(1)); | ||
}); | ||
|
||
it('works with expected promise values', async () => { | ||
await (expect(Promise.resolve([1])).resolves: any).toHaveLengthAsync( | ||
Promise.resolve(1), | ||
); | ||
}); | ||
|
||
it('works with expected promise values and not', async () => { | ||
await (expect(Promise.resolve([1, 2])).resolves.not: any).toHaveLengthAsync( | ||
Promise.resolve(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
Oops, something went wrong.