-
Notifications
You must be signed in to change notification settings - Fork 17
Improve toEqualText
error message
#73
Changes from 11 commits
6b3da61
f7ebddb
2b0df09
8622741
e0000e2
94a7808
201ba68
0ac0f31
c51a53b
849a9f9
1ef4af4
493a361
0e3e57b
56c415c
c0d6d21
c23ef18
31b1100
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`toEqualText selector negative 1`] = `"'not-existing' does not equal 'zzzBarzzz' of '#foobar'."`; | ||
exports[`toEqualText element failure 1`] = ` | ||
"[2mexpect([22m[31mreceived[39m[2m).[22mtoEqualText[2m([22m[32mexpected[39m[2m)[22m | ||
|
||
exports[`toEqualText selector positive 1`] = `"'Bar' does equal 'Bar'."`; | ||
Expected: [32m\\"not-existing\\"[39m | ||
Received: [31m\\"zzzBarzzz\\"[39m" | ||
`; | ||
|
||
exports[`toEqualText selector positive frame 1`] = `"'Example Domain' does equal 'Example Domain'."`; | ||
exports[`toEqualText page failure 1`] = ` | ||
"[2mexpect([22m[31mreceived[39m[2m).[22mtoEqualText[2m([22m[32mexpected[39m[2m)[22m | ||
|
||
Expected: [32m\\"not-existing\\"[39m | ||
Received: [31m\\"zzzBarzzz\\"[39m" | ||
`; | ||
|
||
exports[`toEqualText selector negative 1`] = ` | ||
"[2mexpect([22m[31mreceived[39m[2m).[22mtoEqualText[2m([22m[32mexpected[39m[2m)[22m | ||
|
||
Expected: [32m\\"Bar\\"[39m | ||
Received: [31m\\"zzzBarzzz\\"[39m" | ||
`; | ||
|
||
exports[`toEqualText selector not failure 1`] = ` | ||
"[2mexpect([22m[31mreceived[39m[2m).[22mnot[2m.[22mtoEqualText[2m([22m[32mexpected[39m[2m)[22m | ||
|
||
Expected: not [32m\\"Bar\\"[39m" | ||
`; | ||
|
||
exports[`toEqualText selector timeout should throw an error after the timeout exceeds 1`] = `"Error: Timeout exceed for element '#foobar'"`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,4 +113,26 @@ export const getElementText = async ( | |
throw new Error(`Invalid input length: ${args.length}`) | ||
} | ||
|
||
export const quote = (val: string | null) => `'${val}'` | ||
export const quote = (val: string | null) => | ||
mskelton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val === null ? "null" : `'${val}'` | ||
|
||
export const getMessage = ( | ||
{ isNot, promise, utils }: jest.MatcherContext, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also gave the user ability to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, I didn't realize until now that was an option (glossed over it in the readme). What are the use cases for using it without Jest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We allow it to use it in https://github.com/microsoft/playwright-test since its based on https://github.com/microsoft/folio. So we support the use-case of using it fully standalone or with the http://npmjs.com/package/expect library which is also used in folio. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for not responding sooner, got sidetracked with other priorities at work. My plan is to do some additional testing with folio later this week. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idk but i think that we will need the check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so I had a chance to test this out. Turns out the utils I'm using in this PR are available when using import { it, expect } from "@playwright/test";
import matchers from "expect-playwright/lib/matchers";
expect.extend(matchers);
it("is a basic test with the page", async ({ page }) => {
await page.goto("https://playwright.dev/");
await expect(page).toEqualText("h3", "Playwrights");
}); Then it would actually work. Here is what that looks like: The TS definitions would need updating which looks similar to jest: declare namespace folio {
interface Matchers<R> extends PlaywrightMatchers<R> {}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good, regrading types, in the new folio version which gets released soon it will automatically pick up our existing Jest extend types. |
||
matcher: string, | ||
expected: string | null, | ||
received: string | null | ||
) => { | ||
const matcherHint = | ||
utils.matcherHint(matcher, undefined, undefined, { isNot, promise }) + | ||
"\n\n" | ||
|
||
if (isNot) { | ||
return matcherHint + `Expected: not ${utils.printExpected(expected)}` | ||
} else { | ||
return ( | ||
matcherHint + | ||
`Expected: ${utils.printExpected(expected)}\n` + | ||
`Received: ${utils.printReceived(received)}` | ||
) | ||
} | ||
mskelton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the tests to use the matcher directly in the test rather than testing the results of it. The reason for this is that the matcher is now using more of
jest.MatcherContext
such asprintExpected
,matcherHint
, etc.