Skip to content

Commit 1a7dc8f

Browse files
committed
feat: expose configure API on /fixture entyrpoint
1 parent 649d65d commit 1a7dc8f

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

test/fixture/fixture.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as path from 'path'
44
import * as playwright from '@playwright/test'
55

6-
import {fixtures, TestingLibraryFixtures} from '../../lib/fixture'
6+
import {configure, fixtures, TestingLibraryFixtures} from '../../lib/fixture'
77
import {getDocument, within} from '../../lib'
88

99
const test = playwright.test.extend<TestingLibraryFixtures>(fixtures)
@@ -119,18 +119,45 @@ test.describe('lib/fixture.ts', () => {
119119
test('should get text content', async ({page}) => {
120120
const document = await getDocument(page)
121121
const $h3 = await document.$('#scoped h3')
122+
122123
expect(await $h3.textContent()).toEqual('Hello h3')
123124
})
124125

125126
test('should work with destructuring', async ({page}) => {
126127
const document = await getDocument(page)
127128
const scope = await document.$('#scoped')
129+
128130
// eslint-disable-next-line @typescript-eslint/unbound-method
129131
const {queryByText} = within(scope)
132+
130133
expect(await queryByText('Hello h1')).toBeFalsy()
131134
expect(await queryByText('Hello h3')).toBeTruthy()
132135
})
133136

137+
test.describe('configuration', () => {
138+
test.afterEach(() => {
139+
configure({testIdAttribute: 'data-testid'}) // cleanup
140+
})
141+
142+
test('should support custom data-testid attribute name', async ({queries}) => {
143+
configure({testIdAttribute: 'data-id'})
144+
145+
const element = await queries.getByTestId('second-level-header')
146+
147+
expect(await queries.getNodeText(element)).toEqual('Hello h2')
148+
})
149+
150+
test('should support subsequent changing the data-testid attribute names', async ({
151+
queries,
152+
}) => {
153+
configure({testIdAttribute: 'data-id'})
154+
configure({testIdAttribute: 'data-new-id'})
155+
156+
const element = await queries.getByTestId('first-level-header')
157+
158+
expect(await queries.getNodeText(element)).toEqual('Hello h1')
159+
})
160+
})
134161
test.describe('deferred page', () => {
135162
test.beforeEach(async ({page}) => {
136163
await page.goto(`file://${path.join(__dirname, '../fixtures/late-page.html')}`)

0 commit comments

Comments
 (0)