/** * We can only make one test per file, since the debug tool modify in place * the owl object in a way that is difficult to undo. */ import { debugOwl } from "../../tools/debug"; import * as owl from "../../src/index"; import { Component, Env } from "../../src/component/component"; import { xml } from "../../src/tags"; import { useState } from "../../src/hooks"; import { makeTestFixture, makeTestEnv, nextTick } from "../helpers"; let fixture: HTMLElement = makeTestFixture(); let env: Env = makeTestEnv(); Component.env = env; debugOwl(owl, {}); test("can log full lifecycle", async () => { const steps: string[] = []; const log = console.log; console.log = arg => steps.push(arg); class Child extends Component { static template = xml`
child
`; } class Parent extends Component { static template = xml`
`; static components = { Child }; state = useState({ flag: false }); } const parent = new Parent(null, {}); await parent.mount(fixture); parent.state.flag = true; await nextTick(); expect(steps).toEqual([ "[OWL_DEBUG] Parent constructor, props={}", "[OWL_DEBUG] Parent mount", "[OWL_DEBUG] Parent willStart", "[OWL_DEBUG] Parent rendering template", "[OWL_DEBUG] Parent mounted", "[OWL_DEBUG] Parent render", "[OWL_DEBUG] Parent rendering template", "[OWL_DEBUG] Child constructor, props={}", "[OWL_DEBUG] Child willStart", "[OWL_DEBUG] Child rendering template", "[OWL_DEBUG] Parent willPatch", "[OWL_DEBUG] Child mounted", "[OWL_DEBUG] Parent patched" ]); console.log = log; });