@rvoh/psychic-spec-helpers 0.3.1-fgbeta-7 → 0.3.1-fgbeta-9
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 +13 -20
- package/dist/esm/src/feature/matchers/toClickLink.js +2 -2
- package/dist/esm/src/feature/matchers/toClickSelector.js +2 -2
- package/dist/esm/src/feature/matchers/toHaveSelector.js +3 -4
- package/dist/esm/src/feature/matchers/toMatchTextContent.js +3 -6
- package/dist/esm/src/feature/matchers/toNotHaveSelector.js +7 -5
- package/dist/esm/src/feature/matchers/toNotMatchTextContent.js +3 -1
- package/dist/types/src/feature/matchers/toClick.d.ts +4 -1
- package/dist/types/src/feature/matchers/toNotHaveSelector.d.ts +1 -1
- package/package.json +1 -1
- package/src/feature/matchers/toClick.ts +14 -21
- package/src/feature/matchers/toClickLink.ts +1 -2
- package/src/feature/matchers/toClickSelector.ts +1 -2
- package/src/feature/matchers/toHaveSelector.ts +3 -4
- package/src/feature/matchers/toMatchTextContent.ts +3 -6
- package/src/feature/matchers/toNotHaveSelector.ts +7 -5
- package/src/feature/matchers/toNotMatchTextContent.ts +3 -1
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
import { TimeoutError } from 'puppeteer';
|
|
2
|
-
import evaluateWithRetryAndTimeout from '../internal/evaluateWithRetryAndTimeout.js';
|
|
3
|
-
import evaluationFailure from '../internal/evaluationFailure.js';
|
|
4
|
-
import requirePuppeteerPage from '../internal/requirePuppeteerPage.js';
|
|
5
1
|
export default async function toClick(page, expectedText) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const el = await page.locator(`*::-p-text(${expectedText})`).setTimeout(5000).wait();
|
|
10
|
-
await el.click();
|
|
11
|
-
}
|
|
12
|
-
catch (err) {
|
|
13
|
-
if (err instanceof TimeoutError)
|
|
14
|
-
return evaluationFailure(expectedText);
|
|
15
|
-
throw err;
|
|
16
|
-
}
|
|
2
|
+
try {
|
|
3
|
+
const el = await page.waitForSelector(`*::-p-text(${expectedText})`);
|
|
4
|
+
await el.click();
|
|
17
5
|
return {
|
|
18
6
|
pass: true,
|
|
19
|
-
|
|
7
|
+
message: () => {
|
|
8
|
+
throw new Error('Cannot negate toNotMatchTextContent, use toMatchTextContent instead');
|
|
9
|
+
},
|
|
20
10
|
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
return {
|
|
14
|
+
pass: false,
|
|
15
|
+
message: `Expected page to have clickable element with text: "${expectedText}"`,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
25
18
|
}
|
|
@@ -6,8 +6,8 @@ export default async function toClickLink(page, expectedText) {
|
|
|
6
6
|
return await evaluateWithRetryAndTimeout(page, async () => {
|
|
7
7
|
requirePuppeteerPage(page);
|
|
8
8
|
try {
|
|
9
|
-
|
|
10
|
-
await
|
|
9
|
+
;
|
|
10
|
+
(await page.$(`a ::-p-text(${expectedText})`)).click();
|
|
11
11
|
}
|
|
12
12
|
catch (err) {
|
|
13
13
|
if (err instanceof TimeoutError)
|
|
@@ -6,8 +6,8 @@ export default async function toClickSelector(page, cssSelector) {
|
|
|
6
6
|
return await evaluateWithRetryAndTimeout(page, async () => {
|
|
7
7
|
requirePuppeteerPage(page);
|
|
8
8
|
try {
|
|
9
|
-
|
|
10
|
-
await
|
|
9
|
+
;
|
|
10
|
+
(await page.$(cssSelector)).click();
|
|
11
11
|
}
|
|
12
12
|
catch (err) {
|
|
13
13
|
if (err instanceof TimeoutError)
|
|
@@ -3,10 +3,9 @@ export default async function toHaveSelector(page, selector) {
|
|
|
3
3
|
await page.waitForSelector(selector);
|
|
4
4
|
return {
|
|
5
5
|
pass: true,
|
|
6
|
-
message: () =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
`,
|
|
6
|
+
message: () => {
|
|
7
|
+
throw new Error('Cannot negate toHaveSelector, use toNotHaveSelector instead');
|
|
8
|
+
},
|
|
10
9
|
};
|
|
11
10
|
}
|
|
12
11
|
catch {
|
|
@@ -3,12 +3,9 @@ export default async function toMatchTextContent(page, text, { selector = 'body'
|
|
|
3
3
|
await page.waitForSelector(`${selector}::-p-text(${text.replace(/"/g, '\\"')})`);
|
|
4
4
|
return {
|
|
5
5
|
pass: true,
|
|
6
|
-
message: () =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
but text was found with that selector
|
|
11
|
-
`,
|
|
6
|
+
message: () => {
|
|
7
|
+
throw new Error('Cannot negate toMatchTextContent, use toNotMatchTextContent instead');
|
|
8
|
+
},
|
|
12
9
|
};
|
|
13
10
|
}
|
|
14
11
|
catch {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import evaluateWithRetryAndTimeout from '../internal/evaluateWithRetryAndTimeout.js';
|
|
2
2
|
import requirePuppeteerPage from '../internal/requirePuppeteerPage.js';
|
|
3
|
-
export default async function toNotHaveSelector(page,
|
|
3
|
+
export default async function toNotHaveSelector(page, selector) {
|
|
4
4
|
return await evaluateWithRetryAndTimeout(page, async () => {
|
|
5
5
|
requirePuppeteerPage(page);
|
|
6
6
|
return {
|
|
7
|
-
pass: !(await page.$(
|
|
8
|
-
actual:
|
|
7
|
+
pass: !(await page.$(selector)),
|
|
8
|
+
actual: selector,
|
|
9
9
|
};
|
|
10
10
|
}, {
|
|
11
|
-
successText:
|
|
12
|
-
|
|
11
|
+
successText: () => {
|
|
12
|
+
throw new Error('Cannot negate toNotHaveSelector, use toHaveSelector instead');
|
|
13
|
+
},
|
|
14
|
+
failureText: r => `Expected ${r} to have selector: ${selector}`,
|
|
13
15
|
});
|
|
14
16
|
}
|
|
@@ -10,7 +10,9 @@ export default async function toNotMatchTextContent(argumentPassedToExpect, expe
|
|
|
10
10
|
actual,
|
|
11
11
|
};
|
|
12
12
|
}, {
|
|
13
|
-
successText:
|
|
13
|
+
successText: () => {
|
|
14
|
+
throw new Error('Cannot negate toNotMatchTextContent, use toMatchTextContent instead');
|
|
15
|
+
},
|
|
14
16
|
failureText: r => `Expected ${r} to match text ${expected}`,
|
|
15
17
|
});
|
|
16
18
|
}
|
package/package.json
CHANGED
|
@@ -4,27 +4,20 @@ import evaluationFailure from '../internal/evaluationFailure.js'
|
|
|
4
4
|
import requirePuppeteerPage from '../internal/requirePuppeteerPage.js'
|
|
5
5
|
|
|
6
6
|
export default async function toClick(page: Page, expectedText: string) {
|
|
7
|
-
|
|
8
|
-
page
|
|
9
|
-
|
|
10
|
-
requirePuppeteerPage(page)
|
|
7
|
+
try {
|
|
8
|
+
const el = await page.waitForSelector(`*::-p-text(${expectedText})`)
|
|
9
|
+
await el!.click()
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
actual: expectedText,
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
successText: () => `Expected page to have clickable element with text: "${expectedText}"`,
|
|
27
|
-
failureText: () => `Expected page not to have clickable element with text: "${expectedText}"`,
|
|
11
|
+
return {
|
|
12
|
+
pass: true,
|
|
13
|
+
message: () => {
|
|
14
|
+
throw new Error('Cannot negate toNotMatchTextContent, use toMatchTextContent instead')
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return {
|
|
19
|
+
pass: false,
|
|
20
|
+
message: `Expected page to have clickable element with text: "${expectedText}"`,
|
|
28
21
|
}
|
|
29
|
-
|
|
22
|
+
}
|
|
30
23
|
}
|
|
@@ -10,8 +10,7 @@ export default async function toClickLink(page: Page, expectedText: string) {
|
|
|
10
10
|
requirePuppeteerPage(page)
|
|
11
11
|
|
|
12
12
|
try {
|
|
13
|
-
|
|
14
|
-
await el.click()
|
|
13
|
+
;(await page.$(`a ::-p-text(${expectedText})`))!.click()
|
|
15
14
|
} catch (err) {
|
|
16
15
|
if (err instanceof TimeoutError) return evaluationFailure(expectedText)
|
|
17
16
|
throw err
|
|
@@ -10,8 +10,7 @@ export default async function toClickSelector(page: Page, cssSelector: string) {
|
|
|
10
10
|
requirePuppeteerPage(page)
|
|
11
11
|
|
|
12
12
|
try {
|
|
13
|
-
|
|
14
|
-
await el.click()
|
|
13
|
+
;(await page.$(cssSelector))!.click()
|
|
15
14
|
} catch (err) {
|
|
16
15
|
if (err instanceof TimeoutError) return evaluationFailure(cssSelector)
|
|
17
16
|
throw err
|
|
@@ -5,10 +5,9 @@ export default async function toHaveSelector(page: Page, selector: string) {
|
|
|
5
5
|
await page.waitForSelector(selector)
|
|
6
6
|
return {
|
|
7
7
|
pass: true,
|
|
8
|
-
message: () =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
`,
|
|
8
|
+
message: () => {
|
|
9
|
+
throw new Error('Cannot negate toHaveSelector, use toNotHaveSelector instead')
|
|
10
|
+
},
|
|
12
11
|
}
|
|
13
12
|
} catch {
|
|
14
13
|
return {
|
|
@@ -9,12 +9,9 @@ export default async function toMatchTextContent(
|
|
|
9
9
|
await page.waitForSelector(`${selector}::-p-text(${text.replace(/"/g, '\\"')})`)
|
|
10
10
|
return {
|
|
11
11
|
pass: true,
|
|
12
|
-
message: () =>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
but text was found with that selector
|
|
17
|
-
`,
|
|
12
|
+
message: () => {
|
|
13
|
+
throw new Error('Cannot negate toMatchTextContent, use toNotMatchTextContent instead')
|
|
14
|
+
},
|
|
18
15
|
}
|
|
19
16
|
} catch {
|
|
20
17
|
return {
|
|
@@ -2,20 +2,22 @@ import { Page } from 'puppeteer'
|
|
|
2
2
|
import evaluateWithRetryAndTimeout from '../internal/evaluateWithRetryAndTimeout.js'
|
|
3
3
|
import requirePuppeteerPage from '../internal/requirePuppeteerPage.js'
|
|
4
4
|
|
|
5
|
-
export default async function toNotHaveSelector(page: Page,
|
|
5
|
+
export default async function toNotHaveSelector(page: Page, selector: string) {
|
|
6
6
|
return await evaluateWithRetryAndTimeout(
|
|
7
7
|
page,
|
|
8
8
|
async () => {
|
|
9
9
|
requirePuppeteerPage(page)
|
|
10
10
|
|
|
11
11
|
return {
|
|
12
|
-
pass: !(await page.$(
|
|
13
|
-
actual:
|
|
12
|
+
pass: !(await page.$(selector)),
|
|
13
|
+
actual: selector,
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
|
-
successText:
|
|
18
|
-
|
|
17
|
+
successText: () => {
|
|
18
|
+
throw new Error('Cannot negate toNotHaveSelector, use toHaveSelector instead')
|
|
19
|
+
},
|
|
20
|
+
failureText: r => `Expected ${r} to have selector: ${selector}`,
|
|
19
21
|
}
|
|
20
22
|
)
|
|
21
23
|
}
|
|
@@ -19,7 +19,9 @@ export default async function toNotMatchTextContent(
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
|
-
successText:
|
|
22
|
+
successText: () => {
|
|
23
|
+
throw new Error('Cannot negate toNotMatchTextContent, use toMatchTextContent instead')
|
|
24
|
+
},
|
|
23
25
|
failureText: r => `Expected ${r} to match text ${expected}`,
|
|
24
26
|
}
|
|
25
27
|
)
|