diff --git a/README.md b/README.md index b85d440..10ed07c 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ const dialogButton = getByAttribute(document.body, 'data-action', /^open/) userEvent.click(dialogButton) -const dialog = await findByAttribute(document.body, 'data-id', 'dialog', undefined, { timeout: 1000 }) +const dialog = await findByAttribute(document.body, 'data-id', 'dialog', { timeout: 1000 }) const usernameInput = getByAttribute(dialog, 'data-name', 'username') const passwordInput = getByAttribute(dialog, 'data-name', 'password') @@ -105,25 +105,36 @@ userEvent.click(loginButton) ## Expose API -This project exposes the following api, and the usage is consistent with the original project [@testing-library/dom](https://github.com/testing-library/dom-testing-library) . +This project exposes the following api, and the usage is consistent with the original project [types-of-queries](https://testing-library.com/docs/queries/about/#types-of-queries). -**BySelector** +* **BySelector** -* getBySelector -* getAllBySelector -* queryBySelector -* queryAllBySelector -* findBySelector -* findAllBySelector + + getBySelector -**ByAttribute** + * getAllBySelector + + * queryBySelector + + * queryAllBySelector + + * findBySelector + + * findAllBySelector + +* **ByAttribute** + + * getByAttribute + + * getAllByAttribute + + * queryByAttribute + + * queryAllByAttribute + + * findByAttribute + + * findAllByAttribute -* getByAttribute -* getAllByAttribute -* queryByAttribute -* queryAllByAttribute -* findByAttribute -* findAllByAttribute diff --git a/__tests__/index.spec.ts b/__tests__/index.spec.ts index 3acecf8..bf80700 100644 --- a/__tests__/index.spec.ts +++ b/__tests__/index.spec.ts @@ -128,7 +128,7 @@ describe('Test byAttribute', () => { const loginButtonRef = getByAttribute(container, 'class', 'login-button') userEvent.click(loginButtonRef) - const messageRef = await findByAttribute(container, 'class', 'message', undefined, { timeout: 2000 }) + const messageRef = await findByAttribute(container, 'class', 'message', { timeout: 2000 }) expect(messageRef.textContent).toBe('Login success') }) @@ -137,15 +137,9 @@ describe('Test byAttribute', () => { const loginButtonRef = getByAttribute(container, 'class', 'login-button') userEvent.click(loginButtonRef) - const [messageRef, closeButtonRef] = await findAllByAttribute( - container, - 'class', - /message|close-button/, - undefined, - { - timeout: 2000 - } - ) + const [messageRef, closeButtonRef] = await findAllByAttribute(container, 'class', /message|close-button/, { + timeout: 2000 + }) expect(messageRef.textContent).toBe('Login success') expect(closeButtonRef.textContent).toBe('close') }) diff --git a/src/queries/byAttribute.ts b/src/queries/byAttribute.ts index 92421e3..abaf2d9 100644 --- a/src/queries/byAttribute.ts +++ b/src/queries/byAttribute.ts @@ -71,22 +71,20 @@ const findAllByAttribute = async ( container: HTMLElement, attribute: string, value: Matcher, - options?: MatcherOptions, - waitForOptions?: WaitForOptions + options?: MatcherOptions & WaitForOptions ): Promise => { // @ts-expect-error -- Incorrect derivation of buildQueries internal type - return (await _findAllByAttribute(container, value, { ...options, attribute }, waitForOptions)) as R[] + return (await _findAllByAttribute(container, value, { ...options, attribute }, options)) as R[] } const findByAttribute = async ( container: HTMLElement, attribute: string, value: Matcher, - options?: MatcherOptions, - waitForOptions?: WaitForOptions + options?: MatcherOptions & WaitForOptions ): Promise => { // @ts-expect-error -- Incorrect derivation of buildQueries internal type - return (await _findByAttribute(container, value, { ...options, attribute }, waitForOptions)) as R + return (await _findByAttribute(container, value, { ...options, attribute }, options)) as R } export { queryByAttribute, queryAllByAttribute, getAllByAttribute, getByAttribute, findAllByAttribute, findByAttribute }