Skip to content

Instantly share code, notes, and snippets.

@hatemhosny
Created March 20, 2022 14:10
Show Gist options
  • Save hatemhosny/8b59f733bc3f62f9a494342e12cf9326 to your computer and use it in GitHub Desktop.
Save hatemhosny/8b59f733bc3f62f9a494342e12cf9326 to your computer and use it in GitHub Desktop.
jest-lite CDN Example
const {
core: { describe, it, expect, run },
enzyme: { mount },
prettify
} = window.jestLite;
function Button({ children }) {
return <button>{children}</button>;
}
describe("<Button />", () => {
it("renders children", () => {
const text = "Click me!";
const button = mount(<Button>{text}</Button>);
expect(button.text()).toBe(text);
});
it("renders as a link", () => {
const button = mount(<Button />);
expect(button.find("a").exists()).toBe(true);
});
it("renders as a button", () => {
const button = mount(<Button />);
expect(button.find("button").exists()).toBe(true);
});
});
prettify.toHTML(run(), document.body);
<script src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/jest-lite@1.0.0-alpha.4/dist/core.js"></script>
<script src="https://unpkg.com/jest-lite@1.0.0-alpha.4/dist/enzyme.js"></script>
<script src="https://unpkg.com/jest-lite@1.0.0-alpha.4/dist/prettify.js"></script>
html,
body {
margin: 0;
height: 100%;
}
<link href="https://unpkg.com/jest-lite@1.0.0-alpha.4/dist/prettify.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment