Skip to content

Commit d141e85

Browse files
authored
Merge pull request #102 from Gpx/disabled-checkbox
Disabled checkbox
2 parents 5a5288f + fb90c56 commit d141e85

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

.all-contributorsrc

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
"code",
3434
"test"
3535
]
36+
},
37+
{
38+
"login": "twhitbeck",
39+
"name": "Tim Whitbeck",
40+
"avatar_url": "https://avatars2.githubusercontent.com/u/762471?v=4",
41+
"profile": "https://github.com/twhitbeck",
42+
"contributions": [
43+
"bug",
44+
"code"
45+
]
3646
}
3747
]
3848
}

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
[![Build Status](https://travis-ci.org/Gpx/user-event.svg?branch=master)](https://travis-ci.org/Gpx/user-event)
1414
[![Maintainability](https://api.codeclimate.com/v1/badges/75f1ff4397e994c6004e/maintainability)](https://codeclimate.com/github/Gpx/user-event/maintainability)
1515
[![Test Coverage](https://api.codeclimate.com/v1/badges/75f1ff4397e994c6004e/test_coverage)](https://codeclimate.com/github/Gpx/user-event/test_coverage)
16-
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors) [![Greenkeeper badge](https://badges.greenkeeper.io/Gpx/user-event.svg)](https://greenkeeper.io/)
16+
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors)
17+
[![Greenkeeper badge](https://badges.greenkeeper.io/Gpx/user-event.svg)](https://greenkeeper.io/)
1718

1819
## The problem
1920

@@ -127,8 +128,7 @@ Thanks goes to these wonderful people
127128

128129
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
129130
<!-- prettier-ignore -->
130-
| [<img src="https://avatars0.githubusercontent.com/u/767959?v=4" width="100px;"/><br /><sub><b>Giorgio Polvara</b></sub>](https://twitter.com/Gpx)<br />[🐛](https://github.com/Gpx/user-event/issues?q=author%3AGpx "Bug reports") [💻](https://github.com/Gpx/user-event/commits?author=Gpx "Code") [📖](https://github.com/Gpx/user-event/commits?author=Gpx "Documentation") [🤔](#ideas-Gpx "Ideas, Planning, & Feedback") [🚇](#infra-Gpx "Infrastructure (Hosting, Build-Tools, etc)") [👀](#review-Gpx "Reviewed Pull Requests") [⚠️](https://github.com/Gpx/user-event/commits?author=Gpx "Tests") | [<img src="https://avatars3.githubusercontent.com/u/7049?v=4" width="100px;"/><br /><sub><b>Weyert de Boer</b></sub>](https://github.com/weyert)<br />[💻](https://github.com/Gpx/user-event/commits?author=weyert "Code") [⚠️](https://github.com/Gpx/user-event/commits?author=weyert "Tests") |
131-
| :---: | :---: |
131+
<table><tr><td align="center"><a href="https://twitter.com/Gpx"><img src="https://avatars0.githubusercontent.com/u/767959?v=4" width="100px;" alt="Giorgio Polvara"/><br /><sub><b>Giorgio Polvara</b></sub></a><br /><a href="https://github.com/Gpx/user-event/issues?q=author%3AGpx" title="Bug reports">🐛</a> <a href="https://github.com/Gpx/user-event/commits?author=Gpx" title="Code">💻</a> <a href="https://github.com/Gpx/user-event/commits?author=Gpx" title="Documentation">📖</a> <a href="#ideas-Gpx" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-Gpx" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#review-Gpx" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/Gpx/user-event/commits?author=Gpx" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/weyert"><img src="https://avatars3.githubusercontent.com/u/7049?v=4" width="100px;" alt="Weyert de Boer"/><br /><sub><b>Weyert de Boer</b></sub></a><br /><a href="https://github.com/Gpx/user-event/commits?author=weyert" title="Code">💻</a> <a href="https://github.com/Gpx/user-event/commits?author=weyert" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/twhitbeck"><img src="https://avatars2.githubusercontent.com/u/762471?v=4" width="100px;" alt="Tim Whitbeck"/><br /><sub><b>Tim Whitbeck</b></sub></a><br /><a href="https://github.com/Gpx/user-event/issues?q=author%3Atwhitbeck" title="Bug reports">🐛</a> <a href="https://github.com/Gpx/user-event/commits?author=twhitbeck" title="Code">💻</a></td></tr></table>
132132

133133
<!-- ALL-CONTRIBUTORS-LIST:END -->
134134

__tests__/click.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { render, cleanup } from "react-testing-library";
2+
import { render, cleanup, fireEvent } from "react-testing-library";
33
import "jest-dom/extend-expect";
44
import userEvent from "../src";
55

@@ -67,6 +67,31 @@ describe("userEvent.click", () => {
6767
expect(getByTestId("element")).toHaveProperty("checked", true);
6868
});
6969

70+
it('should fire the correct events for <input type="checkbox" disabled>', () => {
71+
const events = [];
72+
const eventsHandler = jest.fn(evt => events.push(evt.type));
73+
const { getByTestId } = render(
74+
<input
75+
data-testid="element"
76+
type="checkbox"
77+
onMouseOver={eventsHandler}
78+
onMouseMove={eventsHandler}
79+
onMouseDown={eventsHandler}
80+
onFocus={eventsHandler}
81+
onMouseUp={eventsHandler}
82+
onClick={eventsHandler}
83+
onChange={eventsHandler}
84+
disabled
85+
/>
86+
);
87+
88+
userEvent.click(getByTestId("element"));
89+
90+
expect(events).toEqual([]);
91+
92+
expect(getByTestId("element")).toHaveProperty("checked", false);
93+
});
94+
7095
it("should fire the correct events for <div>", () => {
7196
const events = [];
7297
const eventsHandler = jest.fn(evt => events.push(evt.type));

src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ function clickLabel(label) {
3131
}
3232

3333
function clickCheckbox(checkbox) {
34+
if (checkbox.disabled) return;
35+
3436
fireEvent.mouseOver(checkbox);
3537
fireEvent.mouseMove(checkbox);
3638
fireEvent.mouseDown(checkbox);

0 commit comments

Comments
 (0)