Skip to content

Commit b727fc0

Browse files
authored
Merge pull request testing-library#5 from Gpx/prettier
chore: 🤖 add prettier on before commit
2 parents a343635 + 0136250 commit b727fc0

File tree

4 files changed

+1091
-166
lines changed

4 files changed

+1091
-166
lines changed

__tests__/events.js

+88-88
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import React from 'react'
2-
import { render, cleanup } from 'react-testing-library'
3-
import 'jest-dom/extend-expect'
4-
import userEvent from '../src'
5-
6-
afterEach(cleanup)
7-
8-
describe('fireEvent.click', () => {
9-
it('should fire the correct events for <input>', () => {
10-
const onMouseOver = jest.fn()
11-
const onMouseMove = jest.fn()
12-
const onMouseDown = jest.fn()
13-
const onFocus = jest.fn()
14-
const onMouseUp = jest.fn()
15-
const onClick = jest.fn()
1+
import React from "react";
2+
import { render, cleanup } from "react-testing-library";
3+
import "jest-dom/extend-expect";
4+
import userEvent from "../src";
5+
6+
afterEach(cleanup);
7+
8+
describe("fireEvent.click", () => {
9+
it("should fire the correct events for <input>", () => {
10+
const onMouseOver = jest.fn();
11+
const onMouseMove = jest.fn();
12+
const onMouseDown = jest.fn();
13+
const onFocus = jest.fn();
14+
const onMouseUp = jest.fn();
15+
const onClick = jest.fn();
1616
const { getByTestId } = render(
1717
<input
1818
data-testid="input"
@@ -23,32 +23,32 @@ describe('fireEvent.click', () => {
2323
onMouseUp={onMouseUp}
2424
onClick={onClick}
2525
/>
26-
)
27-
28-
expect(onMouseOver).not.toHaveBeenCalled()
29-
expect(onMouseMove).not.toHaveBeenCalled()
30-
expect(onMouseDown).not.toHaveBeenCalled()
31-
expect(onFocus).not.toHaveBeenCalled()
32-
expect(onMouseUp).not.toHaveBeenCalled()
33-
expect(onClick).not.toHaveBeenCalled()
34-
35-
userEvent.click(getByTestId('input'))
36-
37-
expect(onMouseOver).toHaveBeenCalledTimes(1)
38-
expect(onMouseMove).toHaveBeenCalledTimes(1)
39-
expect(onMouseDown).toHaveBeenCalledTimes(1)
40-
expect(onFocus).toHaveBeenCalledTimes(1)
41-
expect(onMouseUp).toHaveBeenCalledTimes(1)
42-
expect(onClick).toHaveBeenCalledTimes(1)
43-
})
44-
45-
it('should fire the correct events for <div>', () => {
46-
const onMouseOver = jest.fn()
47-
const onMouseMove = jest.fn()
48-
const onMouseDown = jest.fn()
49-
const onFocus = jest.fn()
50-
const onMouseUp = jest.fn()
51-
const onClick = jest.fn()
26+
);
27+
28+
expect(onMouseOver).not.toHaveBeenCalled();
29+
expect(onMouseMove).not.toHaveBeenCalled();
30+
expect(onMouseDown).not.toHaveBeenCalled();
31+
expect(onFocus).not.toHaveBeenCalled();
32+
expect(onMouseUp).not.toHaveBeenCalled();
33+
expect(onClick).not.toHaveBeenCalled();
34+
35+
userEvent.click(getByTestId("input"));
36+
37+
expect(onMouseOver).toHaveBeenCalledTimes(1);
38+
expect(onMouseMove).toHaveBeenCalledTimes(1);
39+
expect(onMouseDown).toHaveBeenCalledTimes(1);
40+
expect(onFocus).toHaveBeenCalledTimes(1);
41+
expect(onMouseUp).toHaveBeenCalledTimes(1);
42+
expect(onClick).toHaveBeenCalledTimes(1);
43+
});
44+
45+
it("should fire the correct events for <div>", () => {
46+
const onMouseOver = jest.fn();
47+
const onMouseMove = jest.fn();
48+
const onMouseDown = jest.fn();
49+
const onFocus = jest.fn();
50+
const onMouseUp = jest.fn();
51+
const onClick = jest.fn();
5252
const { getByTestId } = render(
5353
<div
5454
data-testid="div"
@@ -59,84 +59,84 @@ describe('fireEvent.click', () => {
5959
onMouseUp={onMouseUp}
6060
onClick={onClick}
6161
/>
62-
)
63-
64-
expect(onMouseOver).not.toHaveBeenCalled()
65-
expect(onMouseMove).not.toHaveBeenCalled()
66-
expect(onMouseDown).not.toHaveBeenCalled()
67-
expect(onFocus).not.toHaveBeenCalled()
68-
expect(onMouseUp).not.toHaveBeenCalled()
69-
expect(onClick).not.toHaveBeenCalled()
70-
71-
userEvent.click(getByTestId('div'))
72-
73-
expect(onMouseOver).toHaveBeenCalledTimes(1)
74-
expect(onMouseMove).toHaveBeenCalledTimes(1)
75-
expect(onMouseDown).toHaveBeenCalledTimes(1)
76-
expect(onFocus).not.toHaveBeenCalled()
77-
expect(onMouseUp).toHaveBeenCalledTimes(1)
78-
expect(onClick).toHaveBeenCalledTimes(1)
79-
})
80-
81-
it('toggles the focus', () => {
62+
);
63+
64+
expect(onMouseOver).not.toHaveBeenCalled();
65+
expect(onMouseMove).not.toHaveBeenCalled();
66+
expect(onMouseDown).not.toHaveBeenCalled();
67+
expect(onFocus).not.toHaveBeenCalled();
68+
expect(onMouseUp).not.toHaveBeenCalled();
69+
expect(onClick).not.toHaveBeenCalled();
70+
71+
userEvent.click(getByTestId("div"));
72+
73+
expect(onMouseOver).toHaveBeenCalledTimes(1);
74+
expect(onMouseMove).toHaveBeenCalledTimes(1);
75+
expect(onMouseDown).toHaveBeenCalledTimes(1);
76+
expect(onFocus).not.toHaveBeenCalled();
77+
expect(onMouseUp).toHaveBeenCalledTimes(1);
78+
expect(onClick).toHaveBeenCalledTimes(1);
79+
});
80+
81+
it("toggles the focus", () => {
8282
const { getByTestId } = render(
8383
<React.Fragment>
8484
<input data-testid="A" />
8585
<input data-testid="B" />
8686
</React.Fragment>
87-
)
87+
);
8888

89-
const a = getByTestId('A')
90-
const b = getByTestId('B')
89+
const a = getByTestId("A");
90+
const b = getByTestId("B");
9191

92-
expect(a).not.toHaveFocus()
93-
expect(b).not.toHaveFocus()
92+
expect(a).not.toHaveFocus();
93+
expect(b).not.toHaveFocus();
9494

95-
userEvent.click(a)
96-
expect(a).toHaveFocus()
97-
expect(b).not.toHaveFocus()
95+
userEvent.click(a);
96+
expect(a).toHaveFocus();
97+
expect(b).not.toHaveFocus();
9898

99-
userEvent.click(b)
100-
expect(a).not.toHaveFocus()
101-
expect(a).not.toHaveFocus()
102-
})
99+
userEvent.click(b);
100+
expect(a).not.toHaveFocus();
101+
expect(a).not.toHaveFocus();
102+
});
103103

104-
it('gives focus when clicking a <label> with htmlFor', () => {
104+
it("gives focus when clicking a <label> with htmlFor", () => {
105105
const { getByTestId } = render(
106106
<React.Fragment>
107107
<label htmlFor="input" data-testid="label">
108108
Label
109109
</label>
110110
<input id="input" data-testid="input" />
111111
</React.Fragment>
112-
)
113-
userEvent.click(getByTestId('label'))
114-
expect(getByTestId('input')).toHaveFocus()
115-
})
112+
);
113+
userEvent.click(getByTestId("label"));
114+
expect(getByTestId("input")).toHaveFocus();
115+
});
116116

117-
it('gives focus when clicking a <label> without htmlFor', () => {
117+
it("gives focus when clicking a <label> without htmlFor", () => {
118118
const { getByTestId } = render(
119119
<React.Fragment>
120120
<label data-testid="label">
121121
Label
122122
<input data-testid="input" />
123123
</label>
124124
</React.Fragment>
125-
)
126-
userEvent.click(getByTestId('label'))
127-
expect(getByTestId('input')).toHaveFocus()
128-
})
125+
);
126+
userEvent.click(getByTestId("label"));
127+
expect(getByTestId("input")).toHaveFocus();
128+
});
129129

130-
it('gives focus when clicking on an element contained within a <label>', () => {
130+
it("gives focus when clicking on an element contained within a <label>", () => {
131131
const { getByText, getByTestId } = render(
132132
<React.Fragment>
133133
<label htmlFor="input" data-testid="label">
134134
<span>Label</span>
135135
</label>
136136
<input id="input" data-testid="input" />
137137
</React.Fragment>
138-
)
139-
userEvent.click(getByText('Label'))
138+
);
139+
userEvent.click(getByText("Label"));
140140
//expect(getByTestId('input')).toHaveFocus()
141-
})
142-
})
141+
});
142+
});

0 commit comments

Comments
 (0)