-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add remote-mode to startWorker e2e tests (#6483)
* cleanup the expect.{arrayContaining|objectContaining} calls with a custom matcher
- Loading branch information
Showing
6 changed files
with
196 additions
and
138 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
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,35 @@ | ||
import { expect } from "vitest"; | ||
|
||
interface CustomMatchers { | ||
toContainMatchingObject: (expected: object) => unknown; | ||
} | ||
|
||
declare module "vitest" { | ||
interface Assertion extends CustomMatchers {} | ||
interface AsymmetricMatchersContaining extends CustomMatchers {} | ||
} | ||
|
||
expect.extend({ | ||
// Extend vitest's expect object so that it has our new matcher | ||
toContainMatchingObject(received: object[], expected: object) { | ||
// const matcher = createMatcher(expected); | ||
const pass = received.some((item) => isSubset(expected, item)); | ||
|
||
return { | ||
message: () => `Entry was${this.isNot ? "" : " not"} found in array.`, | ||
pass, | ||
actual: received, | ||
expected: expected, | ||
}; | ||
|
||
function isSubset(subset: object, superset: object) { | ||
// Leverage the existing toMatchObject() behaviour to do the deep matching | ||
try { | ||
expect(superset).toMatchObject(subset); | ||
return true; | ||
} catch (ex) { | ||
return false; | ||
} | ||
} | ||
}, | ||
}); |
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.