Installations
npm install michalchmura-testing-library__user-event
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
12.4.0
NPM Version
6.9.0
Score
68.6
Supply Chain
98.1
Quality
75.2
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (94.81%)
JavaScript (5.19%)
Developer
Download Statistics
Total Downloads
1,176
Last Day
5
Last Week
6
Last Month
8
Last Year
89
GitHub Statistics
2,201 Stars
771 Commits
252 Forks
19 Watching
9 Branches
112 Contributors
Package Meta Information
Latest Version
4.2.4-handle-invalid-htmlFor-fix
Package Id
michalchmura-testing-library__user-event@4.2.4-handle-invalid-htmlFor-fix
Unpacked Size
61.30 kB
Size
13.61 kB
File Count
18
NPM Version
6.9.0
Node Version
12.4.0
Total Downloads
Cumulative downloads
Total Downloads
1,176
Last day
0%
5
Compared to previous day
Last week
0%
6
Compared to previous week
Last month
166.7%
8
Compared to previous month
Last year
-41.1%
89
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Dev Dependencies
21
The problem
From testing-library/dom-testing-library#107:
[...] it is becoming apparent the need to express user actions on a web page using a higher-level abstraction than
fireEvent
The solution
user-event
tries to simulate the real events that would happen in the browser
as the user interacts with it. For example userEvent.click(checkbox)
would
change the state of the checkbox.
The library is still a work in progress and any help is appreciated.
Installation
With NPM:
1npm install @testing-library/user-event --save-dev
With Yarn:
1yarn add @testing-library/user-event --dev
Now simply import it in your tests:
1import userEvent from "@testing-library/user-event"; 2 3// or 4 5var userEvent = require("@testing-library/user-event");
API
click(element)
Clicks element
, depending on what element
is it can have different side
effects.
1import React from "react"; 2import { render } from "@testing-library/react"; 3import userEvent from "@testing-library/user-event"; 4 5const { getByText, getByTestId } = test("click", () => { 6 render( 7 <div> 8 <label htmlFor="checkbox">Check</label> 9 <input id="checkbox" data-testid="checkbox" type="checkbox" /> 10 </div> 11 ); 12}); 13 14userEvent.click(getByText("Check")); 15expect(getByTestId("checkbox")).toHaveAttribute("checked", true);
dblClick(element)
Clicks element
twice, depending on what element
is it can have different
side effects.
1import React from "react"; 2import { render } from "@testing-library/react"; 3import userEvent from "@testing-library/user-event"; 4 5test("double click", () => { 6 const onChange = jest.fn(); 7 const { getByTestId } = render( 8 <input type="checkbox" id="checkbox" onChange={onChange} /> 9 ); 10 const checkbox = getByTestId("checkbox"); 11 userEvent.dblClick(checkbox); 12 expect(onChange).toHaveBeenCalledTimes(2); 13 expect(checkbox).toHaveProperty("checked", false); 14});
type(element, text, [options])
Writes text
inside an <input>
or a <textarea>
.
1import React from "react"; 2import { render } from "@testing-library/react"; 3import userEvent from "@testing-library/user-event"; 4 5const { getByText } = test("click", () => { 6 render(<textarea data-testid="email" />); 7}); 8 9userEvent.type(getByTestId("email"), "Hello, World!"); 10expect(getByTestId("email")).toHaveAttribute("value", "Hello, World!");
If options.allAtOnce
is true
, type
will write text
at once rather than
one character at the time. false
is the default value.
options.delay
is the number of milliseconds that pass between two characters
are typed. By default it's 0. You can use this option if your component has a
different behavior for fast or slow users.
selectOptions(element, values, [options])
Selects the specified option(s) of a <select>
or a <select multiple>
element.
1import React from "react"; 2import { render } from "@testing-library/react"; 3import userEvent from "@testing-library/user-event"; 4 5const { getByTestId } = render( 6 <select multiple data-testid="select-multiple"> 7 <option data-testid="val1" value="1"> 8 1 9 </option> 10 <option data-testid="val2" value="2"> 11 2 12 </option> 13 <option data-testid="val3" value="3"> 14 3 15 </option> 16 </select> 17); 18 19userEvent.selectOptions(getByTestId("select-multiple"), ["1", "3"]); 20 21expect(getByTestId("val1").selected).toBe(true); 22expect(getByTestId("val2").selected).toBe(false); 23expect(getByTestId("val3").selected).toBe(true);
The values
parameter can be either an array of values or a singular scalar
value.
If options.target
parameter is set, it will use its value to extract option to
select.
Contributors
Thanks goes to these wonderful people (emoji key):
Giorgio Polvara 🐛 💻 📖 🤔 🚇 👀 ⚠️ | Weyert de Boer 💻 ⚠️ | Tim Whitbeck 🐛 💻 | Michaël De Boey 📖 | Michael Lasky 💻 📖 🤔 | Ahmad Esmaeilzadeh 📖 | Caleb Eby 💻 🐛 |
Adrià Fontcuberta 🐛 ⚠️ | Sky Wickenden 🐛 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
Found 2/20 approved changesets -- score normalized to 1
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/user-event/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/user-event/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/user-event/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:53: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/user-event/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:55: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/user-event/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:66: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/user-event/ci.yml/main?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 4 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 26 are checked with a SAST tool
Score
3.9
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More