-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests to be resilient to message order
- Loading branch information
1 parent
4edf1bf
commit 3e2c92f
Showing
10 changed files
with
799 additions
and
220 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,23 @@ | ||
const { expect } = require('@jest/globals'); | ||
|
||
// Extend jest matchers with a method to check if an array contains an object | ||
// that matches the expected object. Matching means that actual object contains | ||
// all properties of the expected object with the same values. | ||
function toContainMatch(actual, expected) { | ||
if (!Array.isArray(actual)) { | ||
throw new TypeError('Actual value must be an array!'); | ||
} | ||
|
||
const index = actual.findIndex((item) => | ||
// eslint-disable-next-line implicit-arrow-linebreak | ||
Object.keys(expected).every((key) => this.equals(item[key], expected[key]))); | ||
|
||
const pass = index !== -1; | ||
const message = () => `expected ${this.utils.printReceived(actual)} to contain object ${this.utils.printExpected(expected)}`; | ||
|
||
return { message, pass }; | ||
} | ||
|
||
expect.extend({ | ||
toContainMatch, | ||
}); |
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
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.