Gathering detailed insights and metrics for michalchmura-testing-library__user-event
Gathering detailed insights and metrics for michalchmura-testing-library__user-event
Gathering detailed insights and metrics for michalchmura-testing-library__user-event
Gathering detailed insights and metrics for michalchmura-testing-library__user-event
npm install michalchmura-testing-library__user-event
Typescript
Module System
Node Version
NPM Version
68.6
Supply Chain
98.1
Quality
75.2
Maintenance
100
Vulnerability
100
License
TypeScript (94.81%)
JavaScript (5.19%)
Total Downloads
1,176
Last Day
5
Last Week
6
Last Month
8
Last Year
89
2,201 Stars
771 Commits
252 Forks
19 Watching
9 Branches
112 Contributors
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
Cumulative downloads
Total Downloads
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
1
21
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
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.
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");
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.
Thanks goes to these wonderful people (emoji key):
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
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
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
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