-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add custom matcher for playwright
- Loading branch information
1 parent
a19f9a8
commit f710750
Showing
1 changed file
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"use strict"; | ||
|
||
const { expect, mergeExpects } = require('@playwright/test'); | ||
|
||
// TODO: clean and refactor it, check with the team about bypassing the undefined | ||
const toMatchSnapshotWithArray = expect.extend({ | ||
async toMatchSnapshotWithArray(received) { | ||
const assertionName = "toMatchSnapshotWithArray"; | ||
let pass; | ||
let matcherResult; | ||
try { | ||
const serialized = JSON.stringify(received); | ||
await expect(serialized).toMatchSnapshot(); | ||
pass = true; | ||
} catch (e) { | ||
matcherResult = e.matcherResult; | ||
pass = false; | ||
} | ||
|
||
const message = pass | ||
// eslint-disable-next-line no-undefined | ||
? () => `${this.utils.matcherHint(assertionName, undefined, undefined, { isNot: this.isNot }) | ||
}\n\n` + | ||
`Expected: ${this.isNot ? 'not' : ''}${this.utils.printExpected(matcherResult.actual)}\n${ | ||
matcherResult ? `Received: ${this.utils.printReceived(received)}` : ''}` | ||
// eslint-disable-next-line no-undefined | ||
: () => `${this.utils.matcherHint(assertionName, undefined, undefined, { isNot: this.isNot }) | ||
}\n\n` + | ||
`Expected: ${this.utils.printExpected(matcherResult.actual)}\n${ | ||
matcherResult ? `Received: ${this.utils.printReceived(received)}` : ''}`; | ||
|
||
return { | ||
message, | ||
pass, | ||
name: assertionName, | ||
expected: received, | ||
actual: matcherResult?.actual | ||
} | ||
}, | ||
}) | ||
|
||
module.exports = { | ||
expect: mergeExpects(toMatchSnapshotWithArray) | ||
}; |