-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #778 from barrymcgee/type-button
Convert Button to Typescript
- Loading branch information
Showing
6 changed files
with
44 additions
and
27 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react"; | ||
import { shallow } from "enzyme"; | ||
|
||
import Button from "./Button"; | ||
|
||
describe("Button", () => { | ||
it("should display button text", () => { | ||
const wrapper = shallow( | ||
<Button onClick={() => jest.fn()}>Button text</Button> | ||
); | ||
expect(wrapper.find("button").text()).toStrictEqual("Button text"); | ||
}); | ||
|
||
it("should call handler when clicked", () => { | ||
const handleClick = jest.fn(); | ||
const wrapper = shallow( | ||
<Button onClick={() => handleClick()}>Button text</Button> | ||
); | ||
wrapper.find("button").simulate("click"); | ||
expect(handleClick).toBeCalledTimes(1); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ReactElement } from "react"; | ||
|
||
import "./_button.scss"; | ||
|
||
type Props = { | ||
onClick: () => void; | ||
children: string; | ||
}; | ||
|
||
const Button = ({ onClick, children }: Props): ReactElement => { | ||
return ( | ||
<button className="p-button--filter" onClick={onClick}> | ||
{children} | ||
</button> | ||
); | ||
}; | ||
|
||
export default Button; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module "enzyme"; |