|
3 | 3 | import * as path from 'path'
|
4 | 4 | import * as playwright from '@playwright/test'
|
5 | 5 |
|
6 |
| -import {fixtures, TestingLibraryFixtures} from '../../lib/fixture' |
| 6 | +import {configure, fixtures, TestingLibraryFixtures} from '../../lib/fixture' |
7 | 7 | import {getDocument, within} from '../../lib'
|
8 | 8 |
|
9 | 9 | const test = playwright.test.extend<TestingLibraryFixtures>(fixtures)
|
@@ -119,18 +119,45 @@ test.describe('lib/fixture.ts', () => {
|
119 | 119 | test('should get text content', async ({page}) => {
|
120 | 120 | const document = await getDocument(page)
|
121 | 121 | const $h3 = await document.$('#scoped h3')
|
| 122 | + |
122 | 123 | expect(await $h3.textContent()).toEqual('Hello h3')
|
123 | 124 | })
|
124 | 125 |
|
125 | 126 | test('should work with destructuring', async ({page}) => {
|
126 | 127 | const document = await getDocument(page)
|
127 | 128 | const scope = await document.$('#scoped')
|
| 129 | + |
128 | 130 | // eslint-disable-next-line @typescript-eslint/unbound-method
|
129 | 131 | const {queryByText} = within(scope)
|
| 132 | + |
130 | 133 | expect(await queryByText('Hello h1')).toBeFalsy()
|
131 | 134 | expect(await queryByText('Hello h3')).toBeTruthy()
|
132 | 135 | })
|
133 | 136 |
|
| 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 | + }) |
134 | 161 | test.describe('deferred page', () => {
|
135 | 162 | test.beforeEach(async ({page}) => {
|
136 | 163 | await page.goto(`file://${path.join(__dirname, '../fixtures/late-page.html')}`)
|
|
0 commit comments