-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update remaining enzyme tests to RTL.
- Loading branch information
Showing
6 changed files
with
79 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
import { shallow } from "enzyme"; | ||
import { render, screen } from "@testing-library/react"; | ||
import React from "react"; | ||
|
||
import Form from "./Form"; | ||
|
||
describe("Form ", () => { | ||
it("renders", () => { | ||
const wrapper = shallow(<Form>Test content</Form>); | ||
expect(wrapper).toMatchSnapshot(); | ||
render( | ||
<Form name="this needs a name so RTL can find it">Test content</Form> | ||
); | ||
expect(screen.getByRole("form")).toMatchSnapshot(); | ||
}); | ||
|
||
it("can be inline", () => { | ||
const wrapper = shallow(<Form inline={true} />); | ||
expect(wrapper.prop("className").includes("p-form--inline")).toBe(true); | ||
render(<Form name="this needs a name so RTL can find it" inline={true} />); | ||
expect(screen.getByRole("form")).toHaveClass("p-form--inline"); | ||
}); | ||
|
||
it("can be stacked", () => { | ||
const wrapper = shallow(<Form stacked={true} />); | ||
expect(wrapper.prop("className").includes("p-form--stacked")).toBe(true); | ||
render(<Form name="this needs a name so RTL can find it" stacked={true} />); | ||
expect(screen.getByRole("form")).toHaveClass("p-form--stacked"); | ||
}); | ||
|
||
it("can add additional classes", () => { | ||
const wrapper = shallow(<Form stacked={true} className="extra-class" />); | ||
const className = wrapper.prop("className"); | ||
expect(className.includes("p-form")).toBe(true); | ||
expect(className.includes("extra-class")).toBe(true); | ||
render( | ||
<Form | ||
name="this needs a name so RTL can find it" | ||
stacked={true} | ||
className="extra-class" | ||
/> | ||
); | ||
const form = screen.getByRole("form"); | ||
expect(form).toHaveClass("p-form"); | ||
expect(form).toHaveClass("extra-class"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,31 @@ | ||
import { shallow } from "enzyme"; | ||
import { render } from "@testing-library/react"; | ||
import React from "react"; | ||
|
||
import Icon, { ICONS } from "./Icon"; | ||
|
||
describe("Icon", () => { | ||
it("renders", () => { | ||
const wrapper = shallow(<Icon name={ICONS.success} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
const { container } = render(<Icon name={ICONS.success} />); | ||
// eslint-disable-next-line testing-library/no-node-access | ||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("sets correct class name based on given name", () => { | ||
const wrapper = shallow(<Icon name="test" />); | ||
expect(wrapper.prop("className").includes("p-icon--test")).toBe(true); | ||
const { container } = render(<Icon name="test" />); | ||
// eslint-disable-next-line testing-library/no-node-access | ||
expect(container.firstChild).toHaveClass("p-icon--test"); | ||
}); | ||
|
||
it("can be given a custom class name", () => { | ||
const wrapper = shallow(<Icon className="custom-class" name="test" />); | ||
expect(wrapper.prop("className")).toBe("custom-class p-icon--test"); | ||
const { container } = render(<Icon className="custom-class" name="test" />); | ||
// eslint-disable-next-line testing-library/no-node-access | ||
expect(container.firstChild).toHaveClass("custom-class p-icon--test"); | ||
}); | ||
|
||
it("can be given standard HTML props", () => { | ||
const style = { width: "200px" }; | ||
const wrapper = shallow(<Icon name="test" style={style} />); | ||
expect(wrapper.prop("style")).toBe(style); | ||
const { container } = render(<Icon name="test" style={style} />); | ||
// eslint-disable-next-line testing-library/no-node-access | ||
expect(container.firstChild).toHaveAttribute("style", "width: 200px;"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
exports[`Icon renders 1`] = ` | ||
<i | ||
className="p-icon--success" | ||
class="p-icon--success" | ||
/> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters