Skip to content

Commit df8732b

Browse files
committed
style: fix some lint related things
1 parent 8c5443b commit df8732b

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

lib/extend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {getDocument, getQueriesForElement} from '.'
44
import {ElementHandle, IScopedQueryUtils} from './typedefs'
55

66
let Page
7-
let ElementHandle // eslint-disable-line no-redeclare
7+
let ElementHandle // eslint-disable-line @typescript-eslint/no-redeclare
88

99
function requireOrUndefined(path: string) {
1010
try {

lib/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,16 @@ async function processQuery(handles: IHandleSet): Promise<DOMReturnType> {
9797
try {
9898
const handle = await containerHandle.evaluateHandle(evaluateFn, [fnName, ...argsToForward])
9999
return await covertToElementHandle(handle, fnName.includes('All'))
100-
} catch (err) {
101-
err.message = err.message
102-
.replace(/^.*(?=TestingLibraryElementError:)/, '')
103-
.replace('[fnName]', `[${fnName}]`)
104-
err.stack = err.stack.replace('[fnName]', `[${fnName}]`)
105-
throw err
100+
} catch (error) {
101+
if (error instanceof Error) {
102+
error.message = error.message
103+
.replace(/^.*(?=TestingLibraryElementError:)/, '')
104+
.replace('[fnName]', `[${fnName}]`)
105+
106+
error.stack = error.stack?.replace('[fnName]', `[${fnName}]`)
107+
}
108+
109+
throw error
106110
}
107111
}
108112

test/extend.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('lib/extend.ts', () => {
2121
document = await page.getDocument()
2222
})
2323

24-
it('should extend playwright ElementHandle', async () => {
24+
it('should extend playwright ElementHandle', () => {
2525
expect(typeof document.queryAllByAltText).toBe('function')
2626
})
2727

test/index.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ describe('lib/index.ts', () => {
3333
expect(await queries.getNodeText(element)).toEqual('Hello h1')
3434
})
3535

36-
it('should keep the default data-testid when input passed is invalid', async () => {
37-
;[{}, undefined, null, {testIdAttribute: ''}].forEach(async options => {
36+
it.each([{}, undefined, null, {testIdAttribute: ''}])(
37+
'should keep the default data-testid when input passed is invalid',
38+
async options => {
3839
const document = await getDocument(page)
3940
configure(options as any)
4041
const element = await queries.getByTestId(document, 'testid-label')
4142
expect(await queries.getNodeText(element)).toEqual('Label A')
42-
})
43-
})
43+
},
44+
)
4445

4546
it('should support regex on raw queries object', async () => {
4647
const scope = await page.$('#scoped')
@@ -50,6 +51,9 @@ describe('lib/index.ts', () => {
5051
})
5152

5253
it('should bind getQueriesForElement', async () => {
54+
// FIXME: I think it will take some work to get the types in a
55+
// place to prevent @typescript-eslint from flagging this
56+
// eslint-disable-next-line @typescript-eslint/unbound-method
5357
const {getByText} = getQueriesForElement(await getDocument(page))
5458
const element = await getByText('Hello h1')
5559
expect(await queries.getNodeText(element)).toEqual('Hello h1')
@@ -59,6 +63,9 @@ describe('lib/index.ts', () => {
5963
beforeEach(async () => page.goto(`file://${path.join(__dirname, 'fixtures/late-page.html')}`))
6064

6165
it('should use `wait` properly', async () => {
66+
// FIXME: I think it will take some work to get the types in a
67+
// place to prevent @typescript-eslint from flagging this
68+
// eslint-disable-next-line @typescript-eslint/unbound-method
6269
const {getByText} = getQueriesForElement(await getDocument(page))
6370
// eslint-disable-next-line @typescript-eslint/no-misused-promises
6471
await waitFor(async () => expect(await getByText('Loaded!')).toBeTruthy(), {timeout: 7000})

0 commit comments

Comments
 (0)