Skip to content

Commit

Permalink
Merge pull request #243 from testing-library/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
Gpx committed Apr 16, 2020
2 parents 1af6706 + 0854d90 commit 91f0519
Show file tree
Hide file tree
Showing 12 changed files with 2,195 additions and 1,405 deletions.
48 changes: 24 additions & 24 deletions __tests__/react/click.js
Expand Up @@ -8,9 +8,9 @@ afterEach(cleanup);
describe("userEvent.click", () => {
it.each(["input", "textarea"])(
"should fire the correct events for <%s>",
type => {
(type) => {
const events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const eventsHandler = jest.fn((evt) => events.push(evt.type));
const { getByTestId } = render(
React.createElement(type, {
"data-testid": "element",
Expand All @@ -19,7 +19,7 @@ describe("userEvent.click", () => {
onMouseDown: eventsHandler,
onFocus: eventsHandler,
onMouseUp: eventsHandler,
onClick: eventsHandler
onClick: eventsHandler,
})
);

Expand All @@ -31,14 +31,14 @@ describe("userEvent.click", () => {
"mousedown",
"focus",
"mouseup",
"click"
"click",
]);
}
);

it('should fire the correct events for <input type="checkbox">', () => {
const events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const eventsHandler = jest.fn((evt) => events.push(evt.type));
const { getByTestId } = render(
<input
data-testid="element"
Expand All @@ -62,15 +62,15 @@ describe("userEvent.click", () => {
"focus",
"mouseup",
"click",
"change"
"change",
]);

expect(getByTestId("element")).toHaveProperty("checked", true);
});

it('should fire the correct events for <input type="checkbox" disabled>', () => {
const events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const eventsHandler = jest.fn((evt) => events.push(evt.type));
const { getByTestId } = render(
<input
data-testid="element"
Expand All @@ -95,7 +95,7 @@ describe("userEvent.click", () => {

it('should fire the correct events for <input type="radio">', () => {
const events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const eventsHandler = jest.fn((evt) => events.push(evt.type));
const { getByTestId } = render(
<input
data-testid="element"
Expand All @@ -119,15 +119,15 @@ describe("userEvent.click", () => {
"focus",
"mouseup",
"click",
"change"
"change",
]);

expect(getByTestId("element")).toHaveProperty("checked", true);
});

it('should fire the correct events for <input type="radio" disabled>', () => {
const events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const eventsHandler = jest.fn((evt) => events.push(evt.type));
const { getByTestId } = render(
<input
data-testid="element"
Expand All @@ -152,7 +152,7 @@ describe("userEvent.click", () => {

it("should fire the correct events for <div>", () => {
const events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const eventsHandler = jest.fn((evt) => events.push(evt.type));
const { getByTestId } = render(
<div
data-testid="div"
Expand All @@ -171,7 +171,7 @@ describe("userEvent.click", () => {
"mousemove",
"mousedown",
"mouseup",
"click"
"click",
]);
});

Expand Down Expand Up @@ -200,7 +200,7 @@ describe("userEvent.click", () => {

it("should not blur when mousedown prevents default", () => {
let events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const eventsHandler = jest.fn((evt) => events.push(evt.type));
const commonEvents = {
onBlur: eventsHandler,
onMouseOver: eventsHandler,
Expand All @@ -209,7 +209,7 @@ describe("userEvent.click", () => {
onFocus: eventsHandler,
onMouseUp: eventsHandler,
onClick: eventsHandler,
onChange: eventsHandler
onChange: eventsHandler,
};

const { getByTestId } = render(
Expand All @@ -218,7 +218,7 @@ describe("userEvent.click", () => {
<input
data-testid="B"
{...commonEvents}
onMouseDown={e => {
onMouseDown={(e) => {
e.preventDefault();
eventsHandler(e);
}}
Expand Down Expand Up @@ -246,7 +246,7 @@ describe("userEvent.click", () => {
"mousedown",
"focus",
"mouseup",
"click"
"click",
]);

events = [];
Expand All @@ -262,7 +262,7 @@ describe("userEvent.click", () => {
"mousemove",
"mousedown",
"mouseup",
"click"
"click",
]);

events = [];
Expand All @@ -280,7 +280,7 @@ describe("userEvent.click", () => {
"blur",
"focus",
"mouseup",
"click"
"click",
]);
});

Expand Down Expand Up @@ -312,7 +312,7 @@ describe("userEvent.click", () => {

it.each(["input", "textarea"])(
"gives focus to <%s> when clicking a <label> with htmlFor",
type => {
(type) => {
const { getByTestId } = render(
<React.Fragment>
<label htmlFor="input" data-testid="label">
Expand All @@ -328,7 +328,7 @@ describe("userEvent.click", () => {

it.each(["input", "textarea"])(
"gives focus to <%s> when clicking a <label> without htmlFor",
type => {
(type) => {
const { getByTestId } = render(
<React.Fragment>
<label data-testid="label">
Expand All @@ -344,7 +344,7 @@ describe("userEvent.click", () => {

it.each(["input", "textarea"])(
"gives focus to <%s> when clicking on an element contained within a <label>",
type => {
(type) => {
const { getByText, getByTestId } = render(
<React.Fragment>
<label htmlFor="input" data-testid="label">
Expand Down Expand Up @@ -410,13 +410,13 @@ describe("userEvent.click", () => {

it.each(["input", "textarea"])(
"should not give focus for <%s> when mouseDown is prevented",
type => {
(type) => {
const { getByTestId } = render(
React.createElement(type, {
"data-testid": "element",
onMouseDown: evt => {
onMouseDown: (evt) => {
evt.preventDefault();
}
},
})
);

Expand Down
28 changes: 14 additions & 14 deletions __tests__/react/dblclick.js
Expand Up @@ -8,9 +8,9 @@ afterEach(cleanup);
describe("userEvent.dblClick", () => {
it.each(["input", "textarea"])(
"should fire the correct events for <%s>",
type => {
(type) => {
const events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const eventsHandler = jest.fn((evt) => events.push(evt.type));
const { getByTestId } = render(
React.createElement(type, {
"data-testid": "element",
Expand All @@ -20,7 +20,7 @@ describe("userEvent.dblClick", () => {
onFocus: eventsHandler,
onMouseUp: eventsHandler,
onClick: eventsHandler,
onDoubleClick: eventsHandler
onDoubleClick: eventsHandler,
})
);

Expand All @@ -36,14 +36,14 @@ describe("userEvent.dblClick", () => {
"mousedown",
"mouseup",
"click",
"dblclick"
"dblclick",
]);
}
);

it('should fire the correct events for <input type="checkbox">', () => {
const events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const eventsHandler = jest.fn((evt) => events.push(evt.type));
const { getByTestId } = render(
<input
data-testid="element"
Expand Down Expand Up @@ -71,15 +71,15 @@ describe("userEvent.dblClick", () => {
"mousedown",
"mouseup",
"click",
"change"
"change",
]);

expect(getByTestId("element")).toHaveProperty("checked", false);
});

it("should fire the correct events for <div>", () => {
const events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const eventsHandler = jest.fn((evt) => events.push(evt.type));
const { getByTestId } = render(
<div
data-testid="div"
Expand All @@ -101,13 +101,13 @@ describe("userEvent.dblClick", () => {
"click",
"mousedown",
"mouseup",
"click"
"click",
]);
});

it("should not blur when mousedown prevents default", () => {
let events = [];
const eventsHandler = jest.fn(evt => events.push(evt.type));
const eventsHandler = jest.fn((evt) => events.push(evt.type));
const commonEvents = {
onBlur: eventsHandler,
onMouseOver: eventsHandler,
Expand All @@ -116,7 +116,7 @@ describe("userEvent.dblClick", () => {
onFocus: eventsHandler,
onMouseUp: eventsHandler,
onClick: eventsHandler,
onChange: eventsHandler
onChange: eventsHandler,
};

const { getByTestId } = render(
Expand All @@ -125,7 +125,7 @@ describe("userEvent.dblClick", () => {
<input
data-testid="B"
{...commonEvents}
onMouseDown={e => {
onMouseDown={(e) => {
e.preventDefault();
eventsHandler(e);
}}
Expand Down Expand Up @@ -156,7 +156,7 @@ describe("userEvent.dblClick", () => {
"click",
"mousedown",
"mouseup",
"click"
"click",
]);

events = [];
Expand All @@ -175,7 +175,7 @@ describe("userEvent.dblClick", () => {
"click",
"mousedown",
"mouseup",
"click"
"click",
]);

events = [];
Expand All @@ -196,7 +196,7 @@ describe("userEvent.dblClick", () => {
"click",
"mousedown",
"mouseup",
"click"
"click",
]);
});
});

0 comments on commit 91f0519

Please sign in to comment.