Skip to content

Commit

Permalink
add index tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Jun 18, 2019
1 parent 8fbc9f7 commit 6d63f65
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/moon/test/executor/executor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Moon from "../../src/index";
let root = document.createElement("span");
let eventResult;
window.requestAnimationFrame = (fn) => fn();
root.setAttribute("id", "root");
document.body.appendChild(root);

function shuffle(arr) {
Expand Down
58 changes: 58 additions & 0 deletions packages/moon/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Moon from "../src/index";

window.requestAnimationFrame = (fn) => fn();

test("Moon component function", () => {
Moon({ name: "Test", view: "test" });
expect(typeof Moon.components.Test).toBe("function");
Expand All @@ -9,3 +11,59 @@ test("Moon component function with default data", () => {
Moon({ name: "Test", view: "test", data: { foo: "bar" } });
expect(typeof Moon.components.Test).toBe("function");
});

test("Moon without view error", () => {
console.error = jest.fn();

Moon({ name: "Test" });
expect(console.error).toBeCalled();
});

test("Moon Root component without root error", () => {
console.error = jest.fn();

expect(() => {
Moon({});
}).toThrow();
expect(console.error).toBeCalled();
});

test("Moon with string root", () => {
const root = document.createElement("div");

root.id = "test-index-string-root";

document.body.appendChild(root);

Moon({
root: "#test-index-string-root",
view: `<div id="test-index-string-root">Hello Moon!</div>`
});
expect(root.textContent).toEqual("Hello Moon!");
document.body.removeChild(root);
});

test("Moon component with default data", () => {
const root = document.createElement("div");

root.id = "test-index-default-data";

document.body.appendChild(root);

Moon({
name: "Test",
view: `{foo + " " + bar}`,
data: {
foo: "bar",
bar: "baz"
}
});

Moon({
root: "#test-index-default-data",
view: `<div id="test-index-default-data"><Test foo="Moon"/></div>`
});

expect(root.textContent).toEqual("Moon baz");
document.body.removeChild(root);
});

0 comments on commit 6d63f65

Please sign in to comment.