diff --git a/src/runtime/component_node.ts b/src/runtime/component_node.ts index bffc0fc54..062c275cb 100644 --- a/src/runtime/component_node.ts +++ b/src/runtime/component_node.ts @@ -6,7 +6,7 @@ import { OwlError } from "../common/owl_error"; import { Fiber, makeChildFiber, makeRootFiber, MountFiber, MountOptions } from "./fibers"; import { clearReactivesForCallback, getSubscriptions, reactive, targets } from "./reactivity"; import { STATUS } from "./status"; -import { batched, Callback } from "./utils"; +import { batched, Callback, possiblySync } from "./utils"; let currentNode: ComponentNode | null = null; @@ -128,21 +128,29 @@ export class ComponentNode

implements VNode f.call(component))); - } catch (e) { - this.app.handleError({ node: this, error: e }); - return; - } - if (this.status === STATUS.NEW && this.fiber === fiber) { - fiber.render(); - } + return possiblySync( + () => { + const willStartResults = this.willStart.map((f) => f.call(component)); + if (willStartResults.some((r) => typeof r?.then === "function")) { + return Promise.all(willStartResults); + } + return; + }, + () => { + if (this.status === STATUS.NEW && this.fiber === fiber) { + fiber.render(); + } + }, + (e: any) => { + this.app.handleError({ node: this, error: e }); + } + ); } async render(deep: boolean) { diff --git a/src/runtime/utils.ts b/src/runtime/utils.ts index 7aa9b112f..893437714 100644 --- a/src/runtime/utils.ts +++ b/src/runtime/utils.ts @@ -88,3 +88,20 @@ export class Markup extends String {} export function markup(value: any) { return new Markup(value); } + +export function possiblySync(computation: Function, onSuccess: Function, onError: Function) { + try { + let result; + try { + result = computation(); + } catch (e) { + return onError(e); + } + if (typeof result?.then === "function") { + return result.then(onSuccess, onError); + } + return onSuccess(result); + } catch (e) { + return Promise.reject(e); + } +} diff --git a/tests/components/__snapshots__/concurrency.test.ts.snap b/tests/components/__snapshots__/concurrency.test.ts.snap index e9d6b70cc..331eb0b37 100644 --- a/tests/components/__snapshots__/concurrency.test.ts.snap +++ b/tests/components/__snapshots__/concurrency.test.ts.snap @@ -1861,10 +1861,10 @@ exports[`renderings, destruction, patch, stuff, ... yet another variation 3`] = ) { let { text, createBlock, list, multi, html, toggler, comment } = bdom; - let block3 = createBlock(\`

\`); + let block3 = createBlock(\`\`); return function template(ctx, node, key = \\"\\") { - const b2 = text(\`D\`); + const b2 = text(\`C\`); let hdlr1 = [ctx['increment'], ctx]; let txt1 = ctx['state'].val; const b3 = block3([hdlr1, txt1]); @@ -1878,10 +1878,10 @@ exports[`renderings, destruction, patch, stuff, ... yet another variation 4`] = ) { let { text, createBlock, list, multi, html, toggler, comment } = bdom; - let block3 = createBlock(\`\`); + let block3 = createBlock(\`

\`); return function template(ctx, node, key = \\"\\") { - const b2 = text(\`C\`); + const b2 = text(\`D\`); let hdlr1 = [ctx['increment'], ctx]; let txt1 = ctx['state'].val; const b3 = block3([hdlr1, txt1]); diff --git a/tests/components/concurrency.test.ts b/tests/components/concurrency.test.ts index b6ff3e556..320a0f146 100644 --- a/tests/components/concurrency.test.ts +++ b/tests/components/concurrency.test.ts @@ -206,13 +206,15 @@ test("destroying/recreating a subcomponent, other scenario", async () => { "Parent:willRender", "Child:setup", "Child:willStart", + "Child:willRender", + "Child:rendered", "Parent:rendered", "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:willDestroy", "Parent:willPatch", "Child:mounted", @@ -369,9 +371,9 @@ test("creating two async components, scenario 2", async () => { "Parent:willRender", "ChildA:setup", "ChildA:willStart", - "Parent:rendered", "ChildA:willRender", "ChildA:rendered", + "Parent:rendered", "ChildA:mounted", "Parent:mounted", ] @@ -467,9 +469,9 @@ test("creating two async components, scenario 3 (patching in the same frame)", a "Parent:willRender", "ChildA:setup", "ChildA:willStart", - "Parent:rendered", "ChildA:willRender", "ChildA:rendered", + "Parent:rendered", "ChildA:mounted", "Parent:mounted", ] @@ -550,9 +552,9 @@ test("update a sub-component twice in the same frame", async () => { "Parent:willRender", "ChildA:setup", "ChildA:willStart", - "Parent:rendered", "ChildA:willRender", "ChildA:rendered", + "Parent:rendered", "ChildA:mounted", "Parent:mounted", ] @@ -626,9 +628,9 @@ test("update a sub-component twice in the same frame, 2", async () => { "Parent:willRender", "ChildA:setup", "ChildA:willStart", - "Parent:rendered", "ChildA:willRender", "ChildA:rendered", + "Parent:rendered", "ChildA:mounted", "Parent:mounted", ] @@ -733,13 +735,13 @@ test("properly behave when destroyed/unmounted while rendering ", async () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "SubChild:setup", "SubChild:willStart", - "Child:rendered", "SubChild:willRender", "SubChild:rendered", + "Child:rendered", + "Parent:rendered", "SubChild:mounted", "Child:mounted", "Parent:mounted", @@ -835,13 +837,15 @@ test("rendering component again in next microtick", async () => { "Parent:willRender", "Child:setup", "Child:willStart", + "Child:willRender", + "Child:rendered", "Parent:rendered", "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:willDestroy", "Parent:willPatch", "Child:mounted", @@ -895,13 +899,13 @@ test("concurrent renderings scenario 1", async () => { "ComponentA:willRender", "ComponentB:setup", "ComponentB:willStart", - "ComponentA:rendered", "ComponentB:willRender", "ComponentC:setup", "ComponentC:willStart", - "ComponentB:rendered", "ComponentC:willRender", "ComponentC:rendered", + "ComponentB:rendered", + "ComponentA:rendered", "ComponentC:mounted", "ComponentB:mounted", "ComponentA:mounted", @@ -996,13 +1000,13 @@ test("concurrent renderings scenario 2", async () => { "ComponentA:willRender", "ComponentB:setup", "ComponentB:willStart", - "ComponentA:rendered", "ComponentB:willRender", "ComponentC:setup", "ComponentC:willStart", - "ComponentB:rendered", "ComponentC:willRender", "ComponentC:rendered", + "ComponentB:rendered", + "ComponentA:rendered", "ComponentC:mounted", "ComponentB:mounted", "ComponentA:mounted", @@ -1099,13 +1103,13 @@ test("concurrent renderings scenario 2bis", async () => { "ComponentA:willRender", "ComponentB:setup", "ComponentB:willStart", - "ComponentA:rendered", "ComponentB:willRender", "ComponentC:setup", "ComponentC:willStart", - "ComponentB:rendered", "ComponentC:willRender", "ComponentC:rendered", + "ComponentB:rendered", + "ComponentA:rendered", "ComponentC:mounted", "ComponentB:mounted", "ComponentA:mounted", @@ -1217,17 +1221,17 @@ test("concurrent renderings scenario 3", async () => { "ComponentA:willRender", "ComponentB:setup", "ComponentB:willStart", - "ComponentA:rendered", "ComponentB:willRender", "ComponentC:setup", "ComponentC:willStart", - "ComponentB:rendered", "ComponentC:willRender", "ComponentD:setup", "ComponentD:willStart", - "ComponentC:rendered", "ComponentD:willRender", "ComponentD:rendered", + "ComponentC:rendered", + "ComponentB:rendered", + "ComponentA:rendered", "ComponentD:mounted", "ComponentC:mounted", "ComponentB:mounted", @@ -1343,17 +1347,17 @@ test("concurrent renderings scenario 4", async () => { "ComponentA:willRender", "ComponentB:setup", "ComponentB:willStart", - "ComponentA:rendered", "ComponentB:willRender", "ComponentC:setup", "ComponentC:willStart", - "ComponentB:rendered", "ComponentC:willRender", "ComponentD:setup", "ComponentD:willStart", - "ComponentC:rendered", "ComponentD:willRender", "ComponentD:rendered", + "ComponentC:rendered", + "ComponentB:rendered", + "ComponentA:rendered", "ComponentD:mounted", "ComponentC:mounted", "ComponentB:mounted", @@ -1452,9 +1456,9 @@ test("concurrent renderings scenario 5", async () => { "ComponentA:willRender", "ComponentB:setup", "ComponentB:willStart", - "ComponentA:rendered", "ComponentB:willRender", "ComponentB:rendered", + "ComponentA:rendered", "ComponentB:mounted", "ComponentA:mounted", ] @@ -1540,9 +1544,9 @@ test("concurrent renderings scenario 6", async () => { "ComponentA:willRender", "ComponentB:setup", "ComponentB:willStart", - "ComponentA:rendered", "ComponentB:willRender", "ComponentB:rendered", + "ComponentA:rendered", "ComponentB:mounted", "ComponentA:mounted", ] @@ -1628,9 +1632,9 @@ test("concurrent renderings scenario 7", async () => { "ComponentA:willRender", "ComponentB:setup", "ComponentB:willStart", - "ComponentA:rendered", "ComponentB:willRender", "ComponentB:rendered", + "ComponentA:rendered", "ComponentB:mounted", "ComponentA:mounted", ] @@ -1686,9 +1690,9 @@ test("concurrent renderings scenario 8", async () => { "ComponentA:willRender", "ComponentB:setup", "ComponentB:willStart", - "ComponentA:rendered", "ComponentB:willRender", "ComponentB:rendered", + "ComponentA:rendered", "ComponentB:mounted", "ComponentA:mounted", ] @@ -1789,17 +1793,17 @@ test("concurrent renderings scenario 9", async () => { "ComponentA:willRender", "ComponentB:setup", "ComponentB:willStart", - "ComponentC:setup", - "ComponentC:willStart", - "ComponentA:rendered", "ComponentB:willRender", "ComponentB:rendered", + "ComponentC:setup", + "ComponentC:willStart", "ComponentC:willRender", "ComponentD:setup", "ComponentD:willStart", - "ComponentC:rendered", "ComponentD:willRender", "ComponentD:rendered", + "ComponentC:rendered", + "ComponentA:rendered", "ComponentD:mounted", "ComponentC:mounted", "ComponentB:mounted", @@ -1918,9 +1922,9 @@ test("concurrent renderings scenario 10", async () => { "ComponentA:willRender", "ComponentB:setup", "ComponentB:willStart", - "ComponentA:rendered", "ComponentB:willRender", "ComponentB:rendered", + "ComponentA:rendered", "ComponentB:mounted", "ComponentA:mounted", ] @@ -2010,9 +2014,9 @@ test("concurrent renderings scenario 11", async () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -2086,9 +2090,9 @@ test("concurrent renderings scenario 12", async () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -2175,9 +2179,9 @@ test("concurrent renderings scenario 13", async () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", "Child:willRender", @@ -2201,9 +2205,9 @@ test("concurrent renderings scenario 13", async () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Parent:willPatch", "Child:mounted", "Parent:patched", @@ -2271,13 +2275,13 @@ test("concurrent renderings scenario 14", async () => { "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "C:rendered", + "B:rendered", + "A:rendered", "C:mounted", "B:mounted", "A:mounted", @@ -2378,13 +2382,13 @@ test("concurrent renderings scenario 15", async () => { "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "C:rendered", + "B:rendered", + "A:rendered", "C:mounted", "B:mounted", "A:mounted", @@ -2506,13 +2510,13 @@ test("concurrent renderings scenario 16", async () => { "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "C:rendered", + "B:rendered", + "A:rendered", "C:mounted", "B:mounted", "A:mounted", @@ -2722,7 +2726,7 @@ test("changing state before first render does not trigger a render", async () => setup() { useLogLifecycle(); this.state.drinks++; - onWillStart(() => { + onWillStart(async () => { this.state.drinks++; }); } @@ -2757,7 +2761,7 @@ test("changing state before first render does not trigger a render (with parent) setup() { useLogLifecycle(); this.state.drinks++; - onWillStart(() => { + onWillStart(async () => { this.state.drinks++; }); } @@ -2843,9 +2847,9 @@ test("two renderings initiated between willPatch and patched", async () => { "Parent:willRender", "Panel:setup", "Panel:willStart", - "Parent:rendered", "Panel:willRender", "Panel:rendered", + "Parent:rendered", "Panel:mounted", "Parent:mounted", "Parent:willRender", @@ -2881,9 +2885,9 @@ test("two renderings initiated between willPatch and patched", async () => { "Parent:willRender", "Panel:setup", "Panel:willStart", - "Parent:rendered", "Panel:willRender", "Panel:rendered", + "Parent:rendered", "Parent:willPatch", "Panel:willUnmount", "Panel:willDestroy", @@ -2963,9 +2967,9 @@ test("parent and child rendered at exact same time", async () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -3026,9 +3030,9 @@ test("delay willUpdateProps", async () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -3148,17 +3152,17 @@ test("delay willUpdateProps with rendering grandchild", async () => { "GrandParent:willRender", "Parent:setup", "Parent:willStart", - "GrandParent:rendered", "Parent:willRender", "DelayedChild:setup", "DelayedChild:willStart", - "ReactiveChild:setup", - "ReactiveChild:willStart", - "Parent:rendered", "DelayedChild:willRender", "DelayedChild:rendered", + "ReactiveChild:setup", + "ReactiveChild:willStart", "ReactiveChild:willRender", "ReactiveChild:rendered", + "Parent:rendered", + "GrandParent:rendered", "ReactiveChild:mounted", "DelayedChild:mounted", "Parent:mounted", @@ -3266,9 +3270,9 @@ test("two sequential renderings before an animation frame", async () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -3581,9 +3585,9 @@ test("rendering parent twice, with different props on child and stuff", async () "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -3677,17 +3681,17 @@ test("delayed rendering, but then initial rendering is cancelled by yet another "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "D:setup", "D:willStart", - "C:rendered", "D:willRender", "D:rendered", + "C:rendered", + "B:rendered", + "A:rendered", "D:mounted", "C:mounted", "B:mounted", @@ -3798,13 +3802,13 @@ test("delayed rendering, reusing fiber and stuff", async () => { "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "C:rendered", + "B:rendered", + "A:rendered", "C:mounted", "B:mounted", "A:mounted", @@ -3901,13 +3905,13 @@ test("delayed rendering, then component is destroyed and stuff", async () => { "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "C:rendered", + "B:rendered", + "A:rendered", "C:mounted", "B:mounted", "A:mounted", @@ -3989,13 +3993,13 @@ test("delayed rendering, reusing fiber then component is destroyed and stuff", "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "C:rendered", + "B:rendered", + "A:rendered", "C:mounted", "B:mounted", "A:mounted", @@ -4085,13 +4089,13 @@ test("another scenario with delayed rendering", async () => { "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "C:rendered", + "B:rendered", + "A:rendered", "C:mounted", "B:mounted", "A:mounted", @@ -4197,15 +4201,15 @@ test("delayed fiber does not get rendered if it was cancelled", async () => { "A:setup", "A:willRender", "B:setup", - "A:rendered", "B:willRender", "C:setup", - "B:rendered", "C:willRender", "D:setup", - "C:rendered", "D:willRender", "D:rendered", + "C:rendered", + "B:rendered", + "A:rendered", "D:mounted", "C:mounted", "B:mounted", @@ -4310,13 +4314,13 @@ test("destroyed component causes other soon to be destroyed component to rerende "A:willRender", "B:setup", "B:willStart", - "C:setup", - "C:willStart", - "A:rendered", "B:willRender", "B:rendered", + "C:setup", + "C:willStart", "C:willRender", "C:rendered", + "A:rendered", ] `); @@ -4328,13 +4332,13 @@ test("destroyed component causes other soon to be destroyed component to rerende "A:willRender", "B:setup", "B:willStart", - "C:setup", - "C:willStart", - "A:rendered", "B:willRender", "B:rendered", + "C:setup", + "C:willStart", "C:willRender", "C:rendered", + "A:rendered", "B:willDestroy", "C:willDestroy", "A:willPatch", @@ -4399,17 +4403,17 @@ test("delayed rendering, destruction, stuff happens", async () => { "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "D:setup", "D:willStart", - "C:rendered", "D:willRender", "D:rendered", + "C:rendered", + "B:rendered", + "A:rendered", "D:mounted", "C:mounted", "B:mounted", @@ -4506,19 +4510,19 @@ test("renderings, destruction, patch, stuff, ... yet another variation", async ( "A:willRender", "B:setup", "B:willStart", - "D:setup", - "D:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", + "C:willRender", + "C:rendered", "B:rendered", + "D:setup", + "D:willStart", "D:willRender", "D:rendered", - "C:willRender", - "C:rendered", - "C:mounted", + "A:rendered", "D:mounted", + "C:mounted", "B:mounted", "A:mounted", ] @@ -4604,9 +4608,9 @@ test("delayed render does not go through when t-component value changed", async "A:setup", "A:willRender", "B:setup", - "A:rendered", "B:willRender", "B:rendered", + "A:rendered", "B:mounted", "A:mounted", ] @@ -4621,9 +4625,9 @@ test("delayed render does not go through when t-component value changed", async Array [ "A:willRender", "C:setup", - "A:rendered", "C:willRender", "C:rendered", + "A:rendered", "A:willPatch", "B:willUnmount", "B:willDestroy", @@ -4666,9 +4670,9 @@ test("delayed render is not cancelled by upcoming render", async () => { "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "B:rendered", + "A:rendered", "B:mounted", "A:mounted", ] @@ -4785,9 +4789,9 @@ test("components are not destroyed between animation frame", async () => { "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "C:rendered", + "B:rendered", "B:willDestroy", "A:willPatch", "C:mounted", @@ -4824,9 +4828,9 @@ test("component destroyed just after render", async () => { "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "B:rendered", + "A:rendered", "B:mounted", "A:mounted", ] diff --git a/tests/components/error_handling.test.ts b/tests/components/error_handling.test.ts index 24a178f88..b9b4b36e0 100644 --- a/tests/components/error_handling.test.ts +++ b/tests/components/error_handling.test.ts @@ -76,8 +76,9 @@ describe("basics", () => { } const app = new App(Parent); let error: Error; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow( + await expect(appError).resolves.toThrow( 'Cannot find the definition of component "SomeMispelledComponent"' ); await mountProm; @@ -96,8 +97,9 @@ describe("basics", () => { } const app = new App(Parent, { test: true }); let error: Error; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow( + await expect(appError).resolves.toThrow( 'Cannot find the definition of component "SomeMispelledComponent"' ); await mountProm; @@ -116,8 +118,9 @@ describe("basics", () => { } const app = new App(Parent as typeof Component); let error: Error; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow( + await expect(appError).resolves.toThrow( '"SomeComponent" is not a Component. It must inherit from the Component class' ); await mountProm; @@ -133,8 +136,9 @@ describe("basics", () => { } const app = new App(Parent as typeof Component); let error: Error; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow( + await expect(appError).resolves.toThrow( 'Cannot find the definition of component "MissingChild", missing static components key in parent' ); await mountProm; @@ -197,8 +201,9 @@ function(app, bdom, helpers) { }`; const app = new App(Parent as typeof Component); let error: Error; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow(expectedErrorMessage); + await expect(appError).resolves.toThrow(expectedErrorMessage); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe(expectedErrorMessage); @@ -244,8 +249,9 @@ describe("errors and promises", () => { const app = new App(Root); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occured in the owl lifecycle"); + await expect(appError).resolves.toThrow("error occured in the owl lifecycle"); await mountProm; expect(error!).toBeDefined(); expect(error!.cause).toBeDefined(); @@ -268,8 +274,9 @@ describe("errors and promises", () => { const app = new App(Root); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occured in the owl lifecycle"); + await expect(appError).resolves.toThrow("error occured in the owl lifecycle"); await mountProm; expect(error!).toBeDefined(); expect(error!.cause).toBeDefined(); @@ -291,8 +298,9 @@ describe("errors and promises", () => { const app = new App(Root, { test: true }); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occurred in onMounted"); + await expect(appError).resolves.toThrow("error occurred in onMounted"); await mountProm; expect(error!).toBeDefined(); expect(error!.stack).toContain("Root.setup"); @@ -317,8 +325,9 @@ describe("errors and promises", () => { const app = new App(Root, { test: true }); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occurred in onWillRender"); + await expect(appError).resolves.toThrow("error occurred in onWillRender"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -358,8 +367,9 @@ describe("errors and promises", () => { const app = new App(Root, { test: true }); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occurred in onWillStart"); + await expect(appError).resolves.toThrow("error occurred in onWillStart"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -426,8 +436,9 @@ describe("errors and promises", () => { const app = new App(Parent); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occured in the owl lifecycle"); + await expect(appError).resolves.toThrow("error occured in the owl lifecycle"); await mountProm; expect(error!).toBeDefined(); expect(error!.cause).toBeDefined(); @@ -472,8 +483,9 @@ describe("errors and promises", () => { const app = new App(Parent); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occured in the owl lifecycle"); + await expect(appError).resolves.toThrow("error occured in the owl lifecycle"); await mountProm; expect(error!).toBeDefined(); expect(error!.cause).toBeDefined(); @@ -502,8 +514,9 @@ describe("errors and promises", () => { const app = new App(Example, { test: true }); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occurred in onMounted"); + await expect(appError).resolves.toThrow("error occurred in onMounted"); await mountProm; expect(error!.message).toBe(`The following error occurred in onMounted: "Error in mounted"`); // 1 additional error is logged because the destruction of the app causes @@ -577,9 +590,9 @@ describe("can catch errors", () => { } const app = new App(Root, { test: true }); let error: OwlError; - const crashProm = expect(nextAppError(app)).resolves.toThrow("error occurred in onWillStart"); + const appError = nextAppError(app); await app.mount(fixture).catch((e: Error) => (error = e)); - await crashProm; + await expect(appError).resolves.toThrow("error occurred in onWillStart"); expect(error!.message).toBe( `The following error occurred in onWillStart: "No active component (a hook function should only be called in 'setup')"` ); @@ -599,8 +612,9 @@ describe("can catch errors", () => { } const app = new App(Root, { test: true }); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occurred in onMounted"); + await expect(appError).resolves.toThrow("error occurred in onMounted"); await mountProm; expect(error!.message).toBe(`The following error occurred in onMounted: "test error"`); expect(error!.cause).toBe(err); @@ -621,8 +635,9 @@ describe("can catch errors", () => { } const app = new App(Root, { test: true }); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occurred in onWillStart"); + await expect(appError).resolves.toThrow("error occurred in onWillStart"); await mountProm; expect(error!.message).toBe(`The following error occurred in onWillStart: "test error"`); expect(error!.cause).toBe(err); @@ -642,8 +657,9 @@ describe("can catch errors", () => { } const app = new App(Root); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occured in the owl lifecycle"); + await expect(appError).resolves.toThrow("error occured in the owl lifecycle"); await mountProm; expect(error!.message).toBe( `An error occured in the owl lifecycle (see this Error's "cause" property)` @@ -666,8 +682,9 @@ describe("can catch errors", () => { } const app = new App(Root); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occured in the owl lifecycle"); + await expect(appError).resolves.toThrow("error occured in the owl lifecycle"); await mountProm; expect(error!.message).toBe( `An error occured in the owl lifecycle (see this Error's "cause" property)` @@ -688,8 +705,9 @@ describe("can catch errors", () => { } const app = new App(Root, { test: true }); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("not an Error was thrown in onMounted"); + await expect(appError).resolves.toThrow("not an Error was thrown in onMounted"); await mountProm; expect(error!.message).toBe( `Something that is not an Error was thrown in onMounted (see this Error's "cause" property)` @@ -710,8 +728,9 @@ describe("can catch errors", () => { } const app = new App(Root); let error: OwlError; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occured in the owl lifecycle"); + await expect(appError).resolves.toThrow("error occured in the owl lifecycle"); await mountProm; expect(error!.message).toBe( `An error occured in the owl lifecycle (see this Error's "cause" property)` @@ -956,13 +975,13 @@ describe("can catch errors", () => { "Root:willRender", "ErrorBoundary:setup", "ErrorBoundary:willStart", - "Root:rendered", "ErrorBoundary:willRender", "ErrorComponent:setup", "ErrorComponent:willStart", - "ErrorBoundary:rendered", "ErrorComponent:willRender", "ErrorComponent:rendered", + "ErrorBoundary:rendered", + "Root:rendered", "ErrorComponent:mounted", "boom", "ErrorBoundary:willRender", @@ -1008,9 +1027,9 @@ describe("can catch errors", () => { "Root:willRender", "ErrorComponent:setup", "ErrorComponent:willStart", - "Root:rendered", "ErrorComponent:willRender", "ErrorComponent:rendered", + "Root:rendered", "ErrorComponent:mounted", "boom", "Root:willRender", @@ -1071,17 +1090,17 @@ describe("can catch errors", () => { "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "Boom:setup", "Boom:willStart", - "C:rendered", "Boom:willRender", "Boom:rendered", + "C:rendered", + "B:rendered", + "A:rendered", "Boom:mounted", "boom", "C:willRender", @@ -1144,17 +1163,17 @@ describe("can catch errors", () => { "Root:willRender", "OK:setup", "OK:willStart", - "ErrorBoundary:setup", - "ErrorBoundary:willStart", - "Root:rendered", "OK:willRender", "OK:rendered", + "ErrorBoundary:setup", + "ErrorBoundary:willStart", "ErrorBoundary:willRender", "ErrorComponent:setup", "ErrorComponent:willStart", - "ErrorBoundary:rendered", "ErrorComponent:willRender", "ErrorComponent:rendered", + "ErrorBoundary:rendered", + "Root:rendered", "ErrorComponent:mounted", "boom", "ErrorBoundary:willRender", @@ -1497,9 +1516,9 @@ describe("can catch errors", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -1576,9 +1595,9 @@ describe("can catch errors", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", ] `); parent.state.hasChild = false; diff --git a/tests/components/hooks.test.ts b/tests/components/hooks.test.ts index 7b72e265d..74ea564ce 100644 --- a/tests/components/hooks.test.ts +++ b/tests/components/hooks.test.ts @@ -660,8 +660,9 @@ describe("hooks", () => { let error: OwlError; const app = new App(MyComponent); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occured in the owl lifecycle"); + await expect(appError).resolves.toThrow("error occured in the owl lifecycle"); await mountProm; expect(error!.cause.message).toBe("Intentional error"); // no console.error because the error has been caught in this test diff --git a/tests/components/lifecycle.test.ts b/tests/components/lifecycle.test.ts index a140b2b4a..38ae8ef6e 100644 --- a/tests/components/lifecycle.test.ts +++ b/tests/components/lifecycle.test.ts @@ -463,9 +463,9 @@ describe("lifecycle hooks", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -528,9 +528,9 @@ describe("lifecycle hooks", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -650,9 +650,9 @@ describe("lifecycle hooks", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -712,13 +712,13 @@ describe("lifecycle hooks", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "GrandChild:setup", "GrandChild:willStart", - "Child:rendered", "GrandChild:willRender", "GrandChild:rendered", + "Child:rendered", + "Parent:rendered", "Parent:willPatch", "GrandChild:mounted", "Child:mounted", @@ -834,11 +834,11 @@ describe("lifecycle hooks", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "GrandChild:setup", "GrandChild:willStart", "Child:rendered", + "Parent:rendered", ] `); @@ -878,9 +878,9 @@ describe("lifecycle hooks", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -925,9 +925,9 @@ describe("lifecycle hooks", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -986,9 +986,9 @@ describe("lifecycle hooks", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -1113,21 +1113,21 @@ describe("lifecycle hooks", () => { "A:willRender", "B:setup", "B:willStart", - "C:setup", - "C:willStart", - "A:rendered", "B:willRender", "B:rendered", + "C:setup", + "C:willStart", "C:willRender", "D:setup", "D:willStart", - "E:setup", - "E:willStart", - "C:rendered", "D:willRender", "D:rendered", + "E:setup", + "E:willStart", "E:willRender", "E:rendered", + "C:rendered", + "A:rendered", "E:mounted", "D:mounted", "C:mounted", @@ -1144,9 +1144,9 @@ describe("lifecycle hooks", () => { "C:willRender", "F:setup", "F:willStart", - "C:rendered", "F:willRender", "F:rendered", + "C:rendered", "C:willPatch", "E:willUnmount", "E:willDestroy", @@ -1181,9 +1181,9 @@ describe("lifecycle hooks", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -1209,9 +1209,9 @@ describe("lifecycle hooks", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Parent:willPatch", "Child:mounted", "Parent:patched", @@ -1465,6 +1465,8 @@ describe("lifecycle hooks", () => { "Parent:willRender", "Child:setup", "Child:willStart", + "Child:willRender", + "Child:rendered", "Parent:rendered", "Parent:willUnmount", "Child:willDestroy", diff --git a/tests/components/props.test.ts b/tests/components/props.test.ts index e1a11a9ab..8d80f22c6 100644 --- a/tests/components/props.test.ts +++ b/tests/components/props.test.ts @@ -279,9 +279,9 @@ test("bound functions are considered 'alike'", async () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -341,9 +341,9 @@ test(".alike suffix in a simple case", async () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -403,13 +403,13 @@ test(".alike suffix in a list", async () => { "Parent:willRender", "Todo:setup", "Todo:willStart", - "Todo:setup", - "Todo:willStart", - "Parent:rendered", "Todo:willRender", "Todo:rendered", + "Todo:setup", + "Todo:willStart", "Todo:willRender", "Todo:rendered", + "Parent:rendered", "Todo:mounted", "Todo:mounted", "Parent:mounted", diff --git a/tests/components/props_validation.test.ts b/tests/components/props_validation.test.ts index 265a36ba0..6efb93559 100644 --- a/tests/components/props_validation.test.ts +++ b/tests/components/props_validation.test.ts @@ -51,8 +51,9 @@ describe("props validation", () => { const app = new App(Parent, { test: true }); let error: OwlError | undefined; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow( + await expect(appError).resolves.toThrow( "Invalid props for component 'SubComp': 'message' is missing" ); await mountProm; @@ -80,8 +81,9 @@ describe("props validation", () => { const app = new App(Parent, { test: true }); let error: OwlError | undefined; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow( + await expect(appError).resolves.toThrow( "Invalid props for component 'SubComp': 'message' is missing" ); await mountProm; @@ -131,8 +133,9 @@ describe("props validation", () => { props = {}; let app = new App(Parent, { test: true }); let error: OwlError | undefined; + let appError = nextAppError(app); let mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component '_a'"); + await expect(appError).resolves.toThrow("Invalid props for component '_a'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -148,8 +151,9 @@ describe("props validation", () => { expect(error!).toBeUndefined(); props = { p: test.ko }; app = new App(Parent, { test: true }); + appError = nextAppError(app); mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component '_a'"); + await expect(appError).resolves.toThrow("Invalid props for component '_a'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -183,8 +187,9 @@ describe("props validation", () => { props = {}; let app = new App(Parent, { test: true }); let error: OwlError | undefined; + let appError = nextAppError(app); let mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component '_a'"); + await expect(appError).resolves.toThrow("Invalid props for component '_a'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -200,8 +205,9 @@ describe("props validation", () => { expect(error!).toBeUndefined(); props = { p: test.ko }; app = new App(Parent, { test: true }); + appError = nextAppError(app); mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component '_a'"); + await expect(appError).resolves.toThrow("Invalid props for component '_a'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -240,8 +246,9 @@ describe("props validation", () => { expect(error!).toBeUndefined(); props = { p: 1 }; const app = new App(Parent, { test: true }); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component 'SubComp'"); + await expect(appError).resolves.toThrow("Invalid props for component 'SubComp'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -279,8 +286,9 @@ describe("props validation", () => { expect(error!).toBeUndefined(); props = { p: 1 }; const app = new App(Parent, { test: true }); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component 'SubComp'"); + await expect(appError).resolves.toThrow("Invalid props for component 'SubComp'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe("Invalid props for component 'SubComp': 'p' is not a string"); @@ -316,14 +324,16 @@ describe("props validation", () => { expect(error!).toBeUndefined(); props = { p: [1] }; let app = new App(Parent, { test: true }); + let appError = nextAppError(app); let mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component 'SubComp'"); + await expect(appError).resolves.toThrow("Invalid props for component 'SubComp'"); await mountProm; expect(error!).toBeDefined(); error = undefined; app = new App(Parent, { test: true }); + appError = nextAppError(app); mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component 'SubComp'"); + await expect(appError).resolves.toThrow("Invalid props for component 'SubComp'"); await mountProm; expect(error!).toBeDefined(); }); @@ -365,8 +375,9 @@ describe("props validation", () => { expect(error!).toBeUndefined(); props = { p: [true, 1] }; const app = new App(Parent, { test: true }); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component 'SubComp'"); + await expect(appError).resolves.toThrow("Invalid props for component 'SubComp'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -399,8 +410,9 @@ describe("props validation", () => { expect(error!).toBeUndefined(); props = { p: { id: 1, url: "url", extra: true } }; let app = new App(Parent, { test: true }); + let appError = nextAppError(app); let mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component 'SubComp'"); + await expect(appError).resolves.toThrow("Invalid props for component 'SubComp'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -408,8 +420,9 @@ describe("props validation", () => { ); props = { p: { id: "1", url: "url" } }; app = new App(Parent, { test: true }); + appError = nextAppError(app); mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component 'SubComp'"); + await expect(appError).resolves.toThrow("Invalid props for component 'SubComp'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -418,8 +431,9 @@ describe("props validation", () => { error = undefined; props = { p: { id: 1 } }; app = new App(Parent, { test: true }); + appError = nextAppError(app); mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component 'SubComp'"); + await expect(appError).resolves.toThrow("Invalid props for component 'SubComp'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -465,8 +479,9 @@ describe("props validation", () => { expect(error!).toBeUndefined(); props = { p: { id: 1, url: [12, true] } }; const app = new App(Parent, { test: true }); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component 'SubComp'"); + await expect(appError).resolves.toThrow("Invalid props for component 'SubComp'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -675,8 +690,9 @@ describe("props validation", () => { } let error: Error; const app = new App(Parent, { test: true }); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component 'SubComp'"); + await expect(appError).resolves.toThrow("Invalid props for component 'SubComp'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe("Invalid props for component 'SubComp': 'p' is missing"); @@ -765,8 +781,9 @@ describe("props validation", () => { } let error: Error; const app = new App(Parent, { test: true }); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("Invalid props for component 'Child'"); + await expect(appError).resolves.toThrow("Invalid props for component 'Child'"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( @@ -821,8 +838,9 @@ describe("props validation", () => { const app = new App(Parent, { test: true }); let error: OwlError | undefined; + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow( + await expect(appError).resolves.toThrow( "Invalid props for component 'Child': 'message' is missing" ); await mountProm; @@ -895,10 +913,9 @@ describe("default props", () => { } let error: Error; const app = new App(Parent, { test: true }); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow( - "default value cannot be defined for a mandatory prop" - ); + await expect(appError).resolves.toThrow("default value cannot be defined for a mandatory prop"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe( diff --git a/tests/components/reactivity.test.ts b/tests/components/reactivity.test.ts index 042757d56..e7b86963f 100644 --- a/tests/components/reactivity.test.ts +++ b/tests/components/reactivity.test.ts @@ -151,9 +151,10 @@ describe("reactivity in lifecycle", () => { } } const prom = mount(Comp, fixture); + expect(steps).toEqual([1]); (STATE as any).val = 2; await prom; - expect(steps).toEqual([2]); + expect(steps).toEqual([1, 2]); expect(fixture.innerHTML).toBe("
2
"); }); @@ -182,9 +183,9 @@ describe("reactivity in lifecycle", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] diff --git a/tests/components/refs.test.ts b/tests/components/refs.test.ts index b6cf1fb7c..aa5e07954 100644 --- a/tests/components/refs.test.ts +++ b/tests/components/refs.test.ts @@ -125,10 +125,11 @@ describe("refs", () => { } const app = new App(Test, { test: true }); + const appError = nextAppError(app); const mountProm = expect(app.mount(fixture)).rejects.toThrowError( 'Cannot set the same ref more than once in the same component, ref "coucou" was set multiple times in Test' ); - await expect(nextAppError(app)).resolves.toThrow( + await expect(appError).resolves.toThrow( 'Cannot set the same ref more than once in the same component, ref "coucou" was set multiple times in Test' ); await mountProm; diff --git a/tests/components/rendering.test.ts b/tests/components/rendering.test.ts index 2464b6234..8a4e886c0 100644 --- a/tests/components/rendering.test.ts +++ b/tests/components/rendering.test.ts @@ -49,9 +49,9 @@ describe("rendering semantics", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -179,9 +179,9 @@ describe("rendering semantics", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -253,9 +253,9 @@ describe("rendering semantics", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -305,9 +305,9 @@ describe("rendering semantics", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -404,13 +404,13 @@ describe("rendering semantics", () => { "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "C:rendered", + "B:rendered", + "A:rendered", "C:mounted", "B:mounted", "A:mounted", @@ -473,13 +473,13 @@ test("force render in case of existing render", async () => { "A:willRender", "B:setup", "B:willStart", - "A:rendered", "B:willRender", "C:setup", "C:willStart", - "B:rendered", "C:willRender", "C:rendered", + "B:rendered", + "A:rendered", "C:mounted", "B:mounted", "A:mounted", @@ -561,9 +561,9 @@ test("children, default props and renderings", async () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] diff --git a/tests/components/slots.test.ts b/tests/components/slots.test.ts index f36ef6d07..c3a478d33 100644 --- a/tests/components/slots.test.ts +++ b/tests/components/slots.test.ts @@ -223,8 +223,9 @@ describe("slots", () => { let error: Error; const app = new App(Parent); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occured in the owl lifecycle"); + await expect(appError).resolves.toThrow("error occured in the owl lifecycle"); await mountProm; expect(error!).not.toBeNull(); expect(mockConsoleWarn).toBeCalledTimes(1); diff --git a/tests/components/style_class.test.ts b/tests/components/style_class.test.ts index e57dcd5ec..988c12af7 100644 --- a/tests/components/style_class.test.ts +++ b/tests/components/style_class.test.ts @@ -349,8 +349,9 @@ describe("style and class handling", () => { } let error: OwlError; const app = new App(Parent); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occured in the owl lifecycle"); + await expect(appError).resolves.toThrow("error occured in the owl lifecycle"); await mountProm; expect(error!).toBeDefined(); expect(error!.cause).toBeDefined(); diff --git a/tests/components/t_component.test.ts b/tests/components/t_component.test.ts index b682fe535..a32aaff23 100644 --- a/tests/components/t_component.test.ts +++ b/tests/components/t_component.test.ts @@ -36,9 +36,9 @@ describe("t-component", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ] @@ -77,9 +77,9 @@ describe("t-component", () => { "Parent:willRender", "ChildA:setup", "ChildA:willStart", - "Parent:rendered", "ChildA:willRender", "ChildA:rendered", + "Parent:rendered", "ChildA:mounted", "Parent:mounted", ] @@ -94,9 +94,9 @@ describe("t-component", () => { "Parent:willRender", "ChildB:setup", "ChildB:willStart", - "Parent:rendered", "ChildB:willRender", "ChildB:rendered", + "Parent:rendered", "Parent:willPatch", "ChildA:willUnmount", "ChildA:willDestroy", diff --git a/tests/components/t_foreach.test.ts b/tests/components/t_foreach.test.ts index 952d76d93..b570e92bf 100644 --- a/tests/components/t_foreach.test.ts +++ b/tests/components/t_foreach.test.ts @@ -99,13 +99,13 @@ describe("list of components", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Child:setup", - "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Child:setup", + "Child:willStart", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Child:mounted", "Parent:mounted", @@ -326,10 +326,11 @@ describe("list of components", () => { } const app = new App(Parent, { test: true }); + const appError = nextAppError(app); const mountProm = expect(app.mount(fixture)).rejects.toThrow( "Got duplicate key in t-foreach: child" ); - await expect(nextAppError(app)).resolves.toThrow("Got duplicate key in t-foreach: child"); + await expect(appError).resolves.toThrow("Got duplicate key in t-foreach: child"); await mountProm; console.info = consoleInfo; expect(mockConsoleWarn).toBeCalledTimes(1); @@ -352,12 +353,11 @@ describe("list of components", () => { } const app = new App(Parent, { test: true }); + const appError = nextAppError(app); const mountProm = expect(app.mount(fixture)).rejects.toThrow( "Got duplicate key in t-foreach: [object Object]" ); - await expect(nextAppError(app)).resolves.toThrow( - "Got duplicate key in t-foreach: [object Object]" - ); + await expect(appError).resolves.toThrow("Got duplicate key in t-foreach: [object Object]"); await mountProm; console.info = consoleInfo; expect(mockConsoleWarn).toBeCalledTimes(1); diff --git a/tests/helpers.ts b/tests/helpers.ts index 377d99531..f5515d900 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -235,7 +235,7 @@ expect.extend({ }; const currentSteps = steps.splice(0); - const pass = this.equals(currentSteps, expected); + let pass = this.equals(currentSteps, expected); const message = pass ? () => diff --git a/tests/misc/portal.test.ts b/tests/misc/portal.test.ts index e07d524fa..3e6e74ced 100644 --- a/tests/misc/portal.test.ts +++ b/tests/misc/portal.test.ts @@ -270,8 +270,9 @@ describe("Portal", () => { let error: Error; const app = new App(Parent); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("invalid portal target"); + await expect(appError).resolves.toThrow("invalid portal target"); await mountProm; expect(error!).toBeDefined(); @@ -1002,8 +1003,9 @@ describe("Portal: Props validation", () => { } let error: OwlError; const app = new App(Parent); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("error occured in the owl lifecycle"); + await expect(appError).resolves.toThrow("error occured in the owl lifecycle"); await mountProm; expect(error!).toBeDefined(); expect(error!.cause).toBeDefined(); @@ -1021,8 +1023,9 @@ describe("Portal: Props validation", () => { } let error: Error; const app = new App(Parent); + const appError = nextAppError(app); const mountProm = app.mount(fixture).catch((e: Error) => (error = e)); - await expect(nextAppError(app)).resolves.toThrow("invalid portal target"); + await expect(appError).resolves.toThrow("invalid portal target"); await mountProm; expect(error!).toBeDefined(); expect(error!.message).toBe(`invalid portal target`); diff --git a/tests/reactivity.test.ts b/tests/reactivity.test.ts index d1adda0ea..081bcc1e3 100644 --- a/tests/reactivity.test.ts +++ b/tests/reactivity.test.ts @@ -1858,13 +1858,13 @@ describe("Reactivity: useState", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Child:setup", - "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Child:setup", + "Child:willStart", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Child:mounted", "Parent:mounted", @@ -1916,13 +1916,13 @@ describe("Reactivity: useState", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Child:setup", - "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Child:setup", + "Child:willStart", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Child:mounted", "Parent:mounted", @@ -1992,17 +1992,17 @@ describe("Reactivity: useState", () => { "GrandFather:willRender", "Child:setup", "Child:willStart", - "Parent:setup", - "Parent:willStart", - "GrandFather:rendered", "Child:willRender", "Child:rendered", + "Parent:setup", + "Parent:willStart", "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", + "GrandFather:rendered", "Child:mounted", "Parent:mounted", "Child:mounted", @@ -2215,9 +2215,9 @@ describe("Reactivity: useState", () => { "Parent:willRender", "Child:setup", "Child:willStart", - "Parent:rendered", "Child:willRender", "Child:rendered", + "Parent:rendered", "Child:mounted", "Parent:mounted", ]