Skip to content

Commit d9be1df

Browse files
committed
tests: add basic e2e testing
1 parent efa6060 commit d9be1df

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"lint:ts": "tslint -c tslint.json './packages/**/*.ts*(x)'",
1616
"release": "lerna version prerelease",
1717
"pretest": "npm-run-all lint",
18-
"test": "echo \"Tests coming soon. I'm aware that's not ideal.\""
18+
"test": "jest"
1919
},
2020
"dependencies": {
2121
"react": "^16.5.0",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`reactFromMarkupContainer E2E tests Should rehydrate a basic component 1`] = `
4+
"
5+
<div data-react-from-markup-container=\\"\\">
6+
<span>rehydrated component</span>
7+
</div>"
8+
`;
9+
10+
exports[`reactFromMarkupContainer E2E tests Should rehydrate valid HTML markup 1`] = `
11+
"
12+
<div data-react-from-markup-container=\\"\\">
13+
<p>paragraph</p>
14+
</div>"
15+
`;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* eslint-env jest */
2+
import * as React from "react";
3+
import reactFromMarkupContainer from "..";
4+
5+
describe("reactFromMarkupContainer E2E tests", async () => {
6+
it("Should rehydrate a basic component", async () => {
7+
const componentName: string = "myComponent";
8+
9+
const rehydrator = async () => {
10+
return React.createElement("span", {}, "rehydrated component");
11+
};
12+
13+
const rehydrators = { [componentName]: rehydrator };
14+
const documentElement = document.createElement("div");
15+
16+
documentElement.innerHTML = `
17+
<div data-react-from-markup-container>
18+
<div data-rehydratable="${componentName}"></div>
19+
</div>`;
20+
21+
await reactFromMarkupContainer(documentElement, rehydrators, {
22+
extra: {}
23+
});
24+
25+
expect(documentElement.innerHTML).toMatchSnapshot();
26+
});
27+
28+
it("Should rehydrate valid HTML markup", async () => {
29+
const documentElement = document.createElement("div");
30+
31+
documentElement.innerHTML = `
32+
<div data-react-from-markup-container>
33+
<p>paragraph</p>
34+
</div>`;
35+
36+
await reactFromMarkupContainer(documentElement, {}, { extra: {} });
37+
38+
expect(documentElement.innerHTML).toMatchSnapshot();
39+
});
40+
});

0 commit comments

Comments
 (0)