-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5787b47
commit 13e1b32
Showing
10 changed files
with
126 additions
and
32 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 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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import crel from "crel"; | ||
|
||
export default function CustomButton({ content, onClick } = {}) { | ||
const Button = crel("button", content); | ||
|
||
if (onClick) Button.addEventListener("click", onClick); | ||
|
||
return 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,27 @@ | ||
import CustomButton from "./custom-button"; | ||
|
||
test("Custom button renders without crashing", () => { | ||
expect(!!CustomButton()).toBe(true); | ||
}); | ||
test("Custom button calls onClick", () => { | ||
const onClick = jest.fn(); | ||
const customButton = CustomButton({ onClick }); | ||
|
||
customButton.click(); | ||
|
||
expect(onClick).toHaveBeenCalled(); | ||
}); | ||
test("Custom button accepts string content", () => { | ||
const customButton = CustomButton({ content: "Hiya!" }); | ||
|
||
expect(customButton.innerHTML).toBe("Hiya!"); | ||
}); | ||
test("Custom button accepts element content", () => { | ||
const content = document.createElement("i"); | ||
content.innerHTML = "Hiya!"; | ||
const customButton = CustomButton({ content }); | ||
|
||
expect(customButton.innerHTML).toBe("<i>Hiya!</i>"); | ||
expect(customButton.querySelector("i").tagName).toBe("I"); | ||
expect(customButton.querySelector("i").innerHTML).toBe("Hiya!"); | ||
}); |
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
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