@rvoh/psychic-spec-helpers 0.3.1-fgbeta-3 → 0.3.1-fgbeta-5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/src/feature/matchers/toClick.js +1 -1
- package/dist/esm/src/feature/matchers/toHaveSelector.js +20 -2
- package/dist/esm/src/feature/matchers/toMatchTextContent.js +23 -1
- package/dist/types/src/feature/matchers/toHaveSelector.d.ts +4 -1
- package/dist/types/src/feature/matchers/toMatchTextContent.d.ts +4 -1
- package/dist/types/src/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/feature/matchers/toClick.ts +1 -1
- package/src/feature/matchers/toHaveSelector.ts +19 -2
- package/src/feature/matchers/toMatchTextContent.ts +22 -1
- package/src/index.ts +1 -1
|
@@ -6,7 +6,7 @@ export default async function toClick(page, expectedText) {
|
|
|
6
6
|
return await evaluateWithRetryAndTimeout(page, async () => {
|
|
7
7
|
requirePuppeteerPage(page);
|
|
8
8
|
try {
|
|
9
|
-
const el = await page.locator(
|
|
9
|
+
const el = await page.locator(`*::-p-text(${expectedText})`).setTimeout(5000).wait();
|
|
10
10
|
await el.click();
|
|
11
11
|
}
|
|
12
12
|
catch (err) {
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
export default async function toHaveSelector(page,
|
|
2
|
-
|
|
1
|
+
export default async function toHaveSelector(page, selector) {
|
|
2
|
+
try {
|
|
3
|
+
await page.waitForSelector(selector);
|
|
4
|
+
return {
|
|
5
|
+
pass: true,
|
|
6
|
+
message: () => `
|
|
7
|
+
expected no selector: ${selector}
|
|
8
|
+
but the selector was found
|
|
9
|
+
`,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return {
|
|
14
|
+
pass: false,
|
|
15
|
+
message: () => `
|
|
16
|
+
expected selector: ${selector}
|
|
17
|
+
but no selector was found
|
|
18
|
+
`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
3
21
|
}
|
|
@@ -1,3 +1,25 @@
|
|
|
1
1
|
export default async function toMatchTextContent(page, text, { selector = 'body' } = {}) {
|
|
2
|
-
|
|
2
|
+
try {
|
|
3
|
+
await page.waitForSelector(`${selector}::-p-text(${text.replace(/"/g, '\\"')})`);
|
|
4
|
+
return {
|
|
5
|
+
pass: true,
|
|
6
|
+
message: () => `
|
|
7
|
+
expected no ${selector} with text:
|
|
8
|
+
${text}
|
|
9
|
+
|
|
10
|
+
but text was found with that selector
|
|
11
|
+
`,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return {
|
|
16
|
+
pass: false,
|
|
17
|
+
message: () => `
|
|
18
|
+
expected ${selector} with text:
|
|
19
|
+
${text}
|
|
20
|
+
|
|
21
|
+
but no text was found within that selector
|
|
22
|
+
`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
3
25
|
}
|
|
@@ -32,7 +32,7 @@ interface PuppeteerAssertions {
|
|
|
32
32
|
toCheck(expected: any): Promise<CustomMatcherResult>;
|
|
33
33
|
toClick(expected: any): Promise<CustomMatcherResult>;
|
|
34
34
|
toClickLink(expected: any): Promise<CustomMatcherResult>;
|
|
35
|
-
|
|
35
|
+
toClickButton(expected: any): Promise<CustomMatcherResult>;
|
|
36
36
|
toClickSelector(expected: any): Promise<CustomMatcherResult>;
|
|
37
37
|
toHavePath(expected: any): Promise<CustomMatcherResult>;
|
|
38
38
|
toHaveUrl(expected: any): Promise<CustomMatcherResult>;
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@ export default async function toClick(page: Page, expectedText: string) {
|
|
|
10
10
|
requirePuppeteerPage(page)
|
|
11
11
|
|
|
12
12
|
try {
|
|
13
|
-
const el = await page.locator(
|
|
13
|
+
const el = await page.locator(`*::-p-text(${expectedText})`).setTimeout(5000).wait()
|
|
14
14
|
await el.click()
|
|
15
15
|
} catch (err) {
|
|
16
16
|
if (err instanceof TimeoutError) return evaluationFailure(expectedText)
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { Page } from 'puppeteer'
|
|
2
2
|
|
|
3
|
-
export default async function toHaveSelector(page: Page,
|
|
4
|
-
|
|
3
|
+
export default async function toHaveSelector(page: Page, selector: string) {
|
|
4
|
+
try {
|
|
5
|
+
await page.waitForSelector(selector)
|
|
6
|
+
return {
|
|
7
|
+
pass: true,
|
|
8
|
+
message: () => `
|
|
9
|
+
expected no selector: ${selector}
|
|
10
|
+
but the selector was found
|
|
11
|
+
`,
|
|
12
|
+
}
|
|
13
|
+
} catch {
|
|
14
|
+
return {
|
|
15
|
+
pass: false,
|
|
16
|
+
message: () => `
|
|
17
|
+
expected selector: ${selector}
|
|
18
|
+
but no selector was found
|
|
19
|
+
`,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
5
22
|
}
|
|
@@ -5,5 +5,26 @@ export default async function toMatchTextContent(
|
|
|
5
5
|
text: string,
|
|
6
6
|
{ selector = 'body' }: { selector?: string } = {}
|
|
7
7
|
) {
|
|
8
|
-
|
|
8
|
+
try {
|
|
9
|
+
await page.waitForSelector(`${selector}::-p-text(${text.replace(/"/g, '\\"')})`)
|
|
10
|
+
return {
|
|
11
|
+
pass: true,
|
|
12
|
+
message: () => `
|
|
13
|
+
expected no ${selector} with text:
|
|
14
|
+
${text}
|
|
15
|
+
|
|
16
|
+
but text was found with that selector
|
|
17
|
+
`,
|
|
18
|
+
}
|
|
19
|
+
} catch {
|
|
20
|
+
return {
|
|
21
|
+
pass: false,
|
|
22
|
+
message: () => `
|
|
23
|
+
expected ${selector} with text:
|
|
24
|
+
${text}
|
|
25
|
+
|
|
26
|
+
but no text was found within that selector
|
|
27
|
+
`,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
9
30
|
}
|
package/src/index.ts
CHANGED
|
@@ -40,7 +40,7 @@ interface PuppeteerAssertions {
|
|
|
40
40
|
toCheck(expected: any): Promise<CustomMatcherResult>
|
|
41
41
|
toClick(expected: any): Promise<CustomMatcherResult>
|
|
42
42
|
toClickLink(expected: any): Promise<CustomMatcherResult>
|
|
43
|
-
|
|
43
|
+
toClickButton(expected: any): Promise<CustomMatcherResult>
|
|
44
44
|
toClickSelector(expected: any): Promise<CustomMatcherResult>
|
|
45
45
|
toHavePath(expected: any): Promise<CustomMatcherResult>
|
|
46
46
|
toHaveUrl(expected: any): Promise<CustomMatcherResult>
|