@rvoh/psychic-spec-helpers 0.3.1-fgbeta-8 → 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.
@@ -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
- return await evaluateWithRetryAndTimeout(page, async () => {
7
- requirePuppeteerPage(page);
8
- try {
9
- ;
10
- (await page.$(`*::-p-text(${expectedText})`)).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
- actual: expectedText,
7
+ message: () => {
8
+ throw new Error('Cannot negate toNotMatchTextContent, use toMatchTextContent instead');
9
+ },
20
10
  };
21
- }, {
22
- successText: () => `Expected page to have clickable element with text: "${expectedText}"`,
23
- failureText: () => `Expected page not to have clickable element with text: "${expectedText}"`,
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
  }
@@ -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
- expected no selector: ${selector}
8
- but the selector was found
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
- expected no ${selector} with text:
8
- ${text}
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, expectedSelector) {
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.$(expectedSelector)),
8
- actual: expectedSelector,
7
+ pass: !(await page.$(selector)),
8
+ actual: selector,
9
9
  };
10
10
  }, {
11
- successText: r => `Expected ${r} not to have selector: ${expectedSelector}`,
12
- failureText: r => `Expected ${r} to have selector: ${expectedSelector}`,
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: r => `Expected ${r} not to match text ${expected}`,
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
  }
@@ -1,5 +1,8 @@
1
1
  import { Page } from 'puppeteer';
2
2
  export default function toClick(page: Page, expectedText: string): Promise<{
3
- message: () => string;
4
3
  pass: boolean;
4
+ message: () => never;
5
+ } | {
6
+ pass: boolean;
7
+ message: string;
5
8
  }>;
@@ -1,5 +1,5 @@
1
1
  import { Page } from 'puppeteer';
2
- export default function toNotHaveSelector(page: Page, expectedSelector: string): Promise<{
2
+ export default function toNotHaveSelector(page: Page, selector: string): Promise<{
3
3
  message: () => string;
4
4
  pass: boolean;
5
5
  }>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@rvoh/psychic-spec-helpers",
4
- "version": "0.3.1-fgbeta-8",
4
+ "version": "0.3.1-fgbeta-9",
5
5
  "description": "psychic framework spec helpers",
6
6
  "main": "./dist/cjs/src/index.js",
7
7
  "module": "./dist/esm/src/index.js",
@@ -4,26 +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
- return await evaluateWithRetryAndTimeout(
8
- page,
9
- async () => {
10
- requirePuppeteerPage(page)
7
+ try {
8
+ const el = await page.waitForSelector(`*::-p-text(${expectedText})`)
9
+ await el!.click()
11
10
 
12
- try {
13
- ;(await page.$(`*::-p-text(${expectedText})`))!.click()
14
- } catch (err) {
15
- if (err instanceof TimeoutError) return evaluationFailure(expectedText)
16
- throw err
17
- }
18
-
19
- return {
20
- pass: true,
21
- actual: expectedText,
22
- }
23
- },
24
- {
25
- successText: () => `Expected page to have clickable element with text: "${expectedText}"`,
26
- 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}"`,
27
21
  }
28
- )
22
+ }
29
23
  }
@@ -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
- expected no selector: ${selector}
10
- but the selector was found
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
- expected no ${selector} with text:
14
- ${text}
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, expectedSelector: string) {
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.$(expectedSelector)),
13
- actual: expectedSelector,
12
+ pass: !(await page.$(selector)),
13
+ actual: selector,
14
14
  }
15
15
  },
16
16
  {
17
- successText: r => `Expected ${r} not to have selector: ${expectedSelector}`,
18
- failureText: r => `Expected ${r} to have selector: ${expectedSelector}`,
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: r => `Expected ${r} not to match text ${expected}`,
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
  )