Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ module.exports = {
'import/no-extraneous-dependencies': ['error', {devDependencies: true}],
},
},
{
files: ['test/fixture/**/*.+(js|ts)'],
rules: {
'jest/no-done-callback': 'off',
},
},
],
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestingLibraryFixtures>(fixtures)
Expand All @@ -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')

Expand Down
17 changes: 10 additions & 7 deletions test/fixture/fixture.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable jest/no-done-callback */

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<TestingLibraryFixtures>(fixtures)

Expand Down Expand Up @@ -149,12 +147,17 @@ 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(await getByTestId('scoped'))

expect(await queryByText('Hello h1')).toBeFalsy()
expect(await queryByText('Hello h3')).toBeTruthy()
})

test('scoping queries with `getQueriesForElement`', async ({queries: {getByTestId}}) => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const {queryByText} = within(scope)
const {queryByText} = getQueriesForElement(await getByTestId('scoped'))

expect(await queryByText('Hello h1')).toBeFalsy()
expect(await queryByText('Hello h3')).toBeTruthy()
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2 data-id="second-level-header">Hello h2</h2>
<input id="label-text-input" type="text" />

<button role="button">getByRole Test</button>
<div id="scoped">
<div id="scoped" data-testid="scoped">
<h3>Hello h3</h3>
</div>

Expand Down