Skip to content

Commit 6274723

Browse files
committed
Separate test files slightly
1 parent b3a22f1 commit 6274723

File tree

4 files changed

+56
-60
lines changed

4 files changed

+56
-60
lines changed

src/content/github.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createStorage, expectToHavePrettierButton } from "./testUtils";
2+
import GitHub from "./github";
3+
4+
test("GitHub", async () => {
5+
// Basis: https://github.com/prettier/prettier-chrome-extension/issues/new
6+
const button = document.createElement("button");
7+
button.innerText = "Comment";
8+
document.body.appendChild(button);
9+
// Hack around JSDOM's lack of offsetHeight support to fix isElementVisible
10+
Object.defineProperty(document.body, "offsetHeight", { value: 1 });
11+
12+
new GitHub(await createStorage());
13+
expectToHavePrettierButton();
14+
});

src/content/index.test.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/content/stackOverflow.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createStorage, expectToHavePrettierButton } from "./testUtils";
2+
import StackOverflow from "./stackOverflow";
3+
4+
test("Stack Overflow", async () => {
5+
// Basis: https://stackoverflow.com/questions/51875054
6+
const button = document.createElement("div");
7+
button.className = "wmd-button-row";
8+
document.body.appendChild(button);
9+
10+
new StackOverflow(await createStorage());
11+
expectToHavePrettierButton();
12+
});

src/content/testUtils.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import "@testing-library/jest-dom/extend-expect";
2+
import Storage from "./storage";
3+
4+
window.chrome = {
5+
runtime: {},
6+
storage: {
7+
onChanged: {
8+
addListener() {}
9+
},
10+
sync: {
11+
get(callback) {
12+
setTimeout(() => callback({}));
13+
}
14+
}
15+
}
16+
};
17+
18+
window.MutationObserver = class {
19+
constructor() {}
20+
observe() {}
21+
};
22+
23+
export function createStorage() {
24+
const storage = new Storage();
25+
return storage.init();
26+
}
27+
28+
export function expectToHavePrettierButton() {
29+
expect(document.querySelector(".prettier-btn")).toHaveTextContent("Prettier");
30+
}

0 commit comments

Comments
 (0)