From 4b9300f9ff0d710b6f085cc75a6f6c9e5e791ceb Mon Sep 17 00:00:00 2001 From: Jamie Rolfs Date: Sun, 10 Apr 2022 02:30:16 -0700 Subject: [PATCH 1/4] build(lint): disable Jest done callback rule in fixture tests via override --- .eslintrc.js | 6 ++++++ test/fixture/fixture.test.ts | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9f0bf10..746309c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,5 +19,11 @@ module.exports = { 'import/no-extraneous-dependencies': ['error', {devDependencies: true}], }, }, + { + files: ['test/fixture/**/*.+(js|ts)'], + rules: { + 'jest/no-done-callback': 'off', + }, + }, ], } diff --git a/test/fixture/fixture.test.ts b/test/fixture/fixture.test.ts index 7a020b9..8f4d302 100644 --- a/test/fixture/fixture.test.ts +++ b/test/fixture/fixture.test.ts @@ -1,5 +1,3 @@ -/* eslint-disable jest/no-done-callback */ - import * as path from 'path' import * as playwright from '@playwright/test' From 9e70608169954ebe7ad9d45660f0b786b2d81e01 Mon Sep 17 00:00:00 2001 From: Jamie Rolfs Date: Sat, 30 Apr 2022 17:19:11 -0700 Subject: [PATCH 2/4] docs(readme): update scoping example in fixture section with correct usage Closes #411 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bf1885d..b29aa28 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ yarn add --dev @playwright-testing-library/test ```ts import {test as baseTest} from '@playwright/test' -import {fixtures, TestingLibraryFixtures} from '@playwright-testing-library/test/fixture' +import {fixtures, within, TestingLibraryFixtures} from '@playwright-testing-library/test/fixture' // As only fixture const test = baseTest.extend(fixtures) @@ -79,8 +79,8 @@ const {expect} = test test('my form', async ({queries: {getByTestId}}) => { const $form = await getByTestId('my-form') - // Scope queries with `getQueriesForElement` - const {getByLabelText} = $form.getQueriesForElement() + // Scope queries with `within` + const {getByLabelText} = within($form) const $email = await getByLabelText('Email') From 6ad3b5e84c8ffc472044737bee8ba4e1dbd7ac81 Mon Sep 17 00:00:00 2001 From: Jamie Rolfs Date: Sat, 30 Apr 2022 17:20:34 -0700 Subject: [PATCH 3/4] test(fixture): make scoping test case more representative of intended usage Also, update the description for the same reason. --- test/fixture/fixture.test.ts | 7 ++----- test/fixtures/page.html | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/test/fixture/fixture.test.ts b/test/fixture/fixture.test.ts index 8f4d302..1890f8f 100644 --- a/test/fixture/fixture.test.ts +++ b/test/fixture/fixture.test.ts @@ -147,12 +147,9 @@ test.describe('lib/fixture.ts', () => { expect(await $h3.textContent()).toEqual('Hello h3') }) - test('should work with destructuring', async ({page}) => { - const document = await getDocument(page) - const scope = await document.$('#scoped') - + test('scoping queries with `within`', async ({queries: {getByTestId}}) => { // eslint-disable-next-line @typescript-eslint/unbound-method - const {queryByText} = within(scope) + const {queryByText} = within(await getByTestId('scoped')) expect(await queryByText('Hello h1')).toBeFalsy() expect(await queryByText('Hello h3')).toBeTruthy() diff --git a/test/fixtures/page.html b/test/fixtures/page.html index 7e17a90..a014c3a 100644 --- a/test/fixtures/page.html +++ b/test/fixtures/page.html @@ -9,7 +9,7 @@

Hello h2

-
+

Hello h3

From ee4f4a6832b413b58a41cd66eb4873b82aa27042 Mon Sep 17 00:00:00 2001 From: Jamie Rolfs Date: Sat, 30 Apr 2022 17:35:00 -0700 Subject: [PATCH 4/4] test(fixture): add test for `getQueriesForElement` as well --- test/fixture/fixture.test.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/fixture/fixture.test.ts b/test/fixture/fixture.test.ts index 1890f8f..067afc4 100644 --- a/test/fixture/fixture.test.ts +++ b/test/fixture/fixture.test.ts @@ -2,7 +2,7 @@ import * as path from 'path' import * as playwright from '@playwright/test' import {configure, fixtures, TestingLibraryFixtures} from '../../lib/fixture' -import {getDocument, within} from '../../lib' +import {getDocument, within, getQueriesForElement} from '../../lib' const test = playwright.test.extend(fixtures) @@ -155,6 +155,14 @@ test.describe('lib/fixture.ts', () => { expect(await queryByText('Hello h3')).toBeTruthy() }) + test('scoping queries with `getQueriesForElement`', async ({queries: {getByTestId}}) => { + // eslint-disable-next-line @typescript-eslint/unbound-method + const {queryByText} = getQueriesForElement(await getByTestId('scoped')) + + expect(await queryByText('Hello h1')).toBeFalsy() + expect(await queryByText('Hello h3')).toBeTruthy() + }) + test.describe('configuration', () => { test.afterEach(() => { configure({testIdAttribute: 'data-testid'}) // cleanup