1
0
Fork 0
mirror of synced 2024-08-16 18:41:37 +12:00
budibase/packages/client/tests/initialiseApp.spec.js

66 lines
1.9 KiB
JavaScript
Raw Normal View History

import { load } from "./testAppDef"
2020-01-25 02:18:31 +13:00
describe("initialiseApp", () => {
it("should populate simple div with initial props", async () => {
const { dom } = await load({
_component: "testlib/div",
className: "my-test-class",
})
2020-01-25 02:18:31 +13:00
expect(dom.window.document.body.children.length).toBe(1)
const child = dom.window.document.body.children[0]
expect(child.className).toBe("my-test-class")
})
2020-01-25 02:18:31 +13:00
it("should populate child component with props", async () => {
const { dom } = await load({
_component: "testlib/div",
_children: [
{
_component: "testlib/h1",
text: "header one",
},
{
_component: "testlib/h1",
text: "header two",
},
],
})
2020-01-25 02:18:31 +13:00
const rootDiv = dom.window.document.body.children[0]
2020-01-25 02:18:31 +13:00
expect(rootDiv.children.length).toBe(2)
expect(rootDiv.children[0].tagName).toBe("H1")
expect(rootDiv.children[0].innerText).toBe("header one")
expect(rootDiv.children[1].tagName).toBe("H1")
expect(rootDiv.children[1].innerText).toBe("header two")
})
2020-01-25 02:18:31 +13:00
it("should append children when told to do so", async () => {
const { dom } = await load({
_component: "testlib/div",
_children: [
{
_component: "testlib/h1",
text: "header one",
},
{
_component: "testlib/h1",
text: "header two",
},
],
append: true,
})
2020-01-25 02:18:31 +13:00
const rootDiv = dom.window.document.body.children[0]
2020-01-25 02:18:31 +13:00
expect(rootDiv.children.length).toBe(3)
expect(rootDiv.children[0].tagName).toBe("DIV")
expect(rootDiv.children[0].className).toBe("default-child")
expect(rootDiv.children[1].tagName).toBe("H1")
expect(rootDiv.children[1].innerText).toBe("header one")
expect(rootDiv.children[2].tagName).toBe("H1")
expect(rootDiv.children[2].innerText).toBe("header two")
})
})