Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

testing-library/testing-library-recorder-extension

octopus

Testing Library Extension for Chrome DevTools Recorder


Build StatusCode CoverageversiondownloadsMIT LicensePRs WelcomeCode of ConductDiscord

Watch on GitHubStar on GitHubTweet

Export tests from the DevTools Recorder panel to Testing Library test scriptsusing Jest.

Open a recording and click export to use the Testing Library script option.

Screenshot

Table of Contents

Usage

Exporting entire workflows

  1. Start or open a recording using the DevTools Recorder panel
  2. ClickExport as a Testing Library script in the toolbar
  3. Save file as{testName}.test.{ts,js}

Exporting individual steps

  1. Start or open a recording using the DevTools Recorder panel
  2. ClickCopy as a Testing Library script in the dropdown or right-click menu
  3. Paste into an existing file

Installing dependencies

npm install --save-dev jest jest-environment-jsdom jest-environment-url @testing-library/dom @testing-library/user-event @testing-library/jest-dom
yarn add --dev jest jest-environment-jsdom jest-environment-url @testing-library/dom @testing-library/user-event @testing-library/jest-dom

Running tests

jest

Supported Chrome Recorder Step Types

TypeOutput
changeawait userEvent.type(element, 'value')
clickawait userEvent.click(element)
click (right)await userEvent.click(element, {buttons: 2})
hoverawait userEvent.hover(element)
doubleClickawait userEvent.dblClick(element)
keyDownawait userEvent.keyboard('{Key>}')
keyUpawait userEvent.keyboard('{/Key}')
navigate *expect(location.href).toBe('https://example.com/')expect(document.title).toBe('Example Domain')
waitForElementawait waitFor(() => element)
waitForExpressionawait waitFor(() => expression)

* Only onenavigate step is allowed per test becausejest-environment-urlmust load pages sincejsdom does not support navigation. Without anynavigate steps, you'll need to edit your test to manually load the DOM.

Example

Recording

{"title":"Example","steps": [    {"type":"navigate","url":"https://example.com/","assertedEvents": [        {"type":"navigation","url":"https://example.com/","title":"Example Domain"        }      ]    },    {"type":"waitForElement","selectors": [        ["aria/More information..."],        ["body > div > p:nth-child(3) > a"],        ["xpath//html/body/div/p[2]/a"],        ["text/More information..."]      ]    }  ]}

Test Output

/** *@jest-environment url *@jest-environment-options { "url": "https://example.com/" } */const{screen, waitFor}=require('@testing-library/dom')const{default:userEvent}=require('@testing-library/user-event')require('@testing-library/jest-dom')test('Example',async()=>{expect(location.href).toBe('https://example.com/')expect(document.title).toBe('Example Domain')awaitwaitFor(()=>screen.getByText('More information...'))})

Inspiration

Issues

Looking to contribute? Look for theGood First Issue label.

🐛 Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior.

See Bugs

💡 Feature Requests

Please file an issue to suggest new features. Vote on feature requests by addinga 👍. This helps maintainers prioritize what to work on.

See Feature Requests

❓ Questions

For questions related to using the library, please visit a support communityinstead of filing an issue on GitHub.

License

MIT

Sponsor this project


    [8]ページ先頭

    ©2009-2025 Movatter.jp