Skip to content
Closed
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
34 changes: 10 additions & 24 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {ElementHandle, EvaluateFn, JSHandle, Page} from 'puppeteer'
import waitForExpect from 'wait-for-expect'
import {IQueryUtils} from './typedefs'

// @ts-ignore
// tslint:disable-next-line
const queries = require('dom-testing-library/dist/queries')

const domLibraryAsString = readFileSync(
path.join(__dirname, '../dom-testing-library.js'),
'utf8',
Expand Down Expand Up @@ -123,32 +127,14 @@ export function wait(
export function getQueriesForElement<T>(object: T, contextFn?: ContextFn): T & IQueryUtils {
const o = object as any
if (!contextFn) contextFn = () => o

Object.entries(queries).map(([fnName]) => {
o[fnName] = createDelegateFor(fnName as keyof IQueryUtils, contextFn)
})

o.getQueriesForElement = () => getQueriesForElement(o, () => o)
o.queryByPlaceholderText = createDelegateFor('queryByPlaceholderText', contextFn)
o.queryAllByPlaceholderText = createDelegateFor('queryAllByPlaceholderText', contextFn)
o.getByPlaceholderText = createDelegateFor('getByPlaceholderText', contextFn)
o.getAllByPlaceholderText = createDelegateFor('getAllByPlaceholderText', contextFn)
o.queryByText = createDelegateFor('queryByText', contextFn)
o.queryAllByText = createDelegateFor('queryAllByText', contextFn)
o.getByText = createDelegateFor('getByText', contextFn)
o.getAllByText = createDelegateFor('getAllByText', contextFn)
o.queryByLabelText = createDelegateFor('queryByLabelText', contextFn)
o.queryAllByLabelText = createDelegateFor('queryAllByLabelText', contextFn)
o.getByLabelText = createDelegateFor('getByLabelText', contextFn)
o.getAllByLabelText = createDelegateFor('getAllByLabelText', contextFn)
o.queryByAltText = createDelegateFor('queryByAltText', contextFn)
o.queryAllByAltText = createDelegateFor('queryAllByAltText', contextFn)
o.getByAltText = createDelegateFor('getByAltText', contextFn)
o.getAllByAltText = createDelegateFor('getAllByAltText', contextFn)
o.queryByTestId = createDelegateFor('queryByTestId', contextFn)
o.queryAllByTestId = createDelegateFor('queryAllByTestId', contextFn)
o.getByTestId = createDelegateFor('getByTestId', contextFn)
o.getAllByTestId = createDelegateFor('getAllByTestId', contextFn)
o.queryByTitle = createDelegateFor('queryByTitle', contextFn)
o.queryAllByTitle = createDelegateFor('queryAllByTitle', contextFn)
o.getByTitle = createDelegateFor('getByTitle', contextFn)
o.getAllByTitle = createDelegateFor('getAllByTitle', contextFn)
o.getNodeText = createDelegateFor<string>('getNodeText', contextFn, processNodeText)

return o
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"test": "npm run test:lint && npm run test:unit",
"test:unit": "jest",
"test:lint": "lint -t typescript './lib/**/*.ts'",
"pretest": "npm run rebuild",
"semantic-release": "semantic-release",
"clean": "rm -fR dist/",
"rebuild": "npm run clean && npm run build",
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compileOnSave": true,
"compilerOptions": {
"outDir": "./dist",
"target": "es2015",
"target": "es2017",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
Expand All @@ -13,6 +13,7 @@
"noImplicitThis": true,
"strictNullChecks": true,
"preserveWatchOutput": true,
"lib": ["es2017", "dom"],
},
"include": [
"lib/**/*"
Expand Down