1- import { Component , mount , onError , OwlError , props , types as t , xml } from "../../src" ;
2- import { App } from "../../src/runtime/app" ;
3- import { makeTestFixture , nextAppError , nextTick , render , snapshotEverything } from "../helpers" ;
1+ import { Component , mount , onError , props , types as t , xml } from "../../src" ;
2+ import { makeTestFixture , nextTick , render , snapshotEverything } from "../helpers" ;
43
54let fixture : HTMLElement ;
65
@@ -47,26 +46,22 @@ describe("props validation", () => {
4746 static template = xml `<div><SubComp /></div>` ;
4847 }
4948
50- const app = new App ( { test : true } ) ;
51- let error : OwlError | undefined ;
52- const mountProm = app
53- . createRoot ( Parent )
54- . mount ( fixture )
55- . catch ( ( e : Error ) => ( error = e ) ) ;
56- await expect ( nextAppError ( app ) ) . resolves . toThrow (
57- "[Owl] Unhandled error. Destroying the root component"
58- ) ;
59- await mountProm ;
60- expect ( error ! ) . toBeDefined ( ) ;
61- expect ( error ! . cause . message ) . toMatch ( "Invalid component props (SubComp)" ) ;
62- error = undefined ;
49+ let error : any ;
50+ try {
51+ await mount ( Parent , fixture , { test : true } ) ;
52+ } catch ( e ) {
53+ error = e ;
54+ }
55+ expect ( error ) . toBeDefined ( ) ;
56+ expect ( error . cause . message ) . toMatch ( "Invalid component props (SubComp)" ) ;
6357
58+ error = undefined ;
6459 try {
6560 await mount ( Parent , fixture , { dev : false } ) ;
6661 } catch ( e ) {
67- error = e as Error ;
62+ error = e ;
6863 }
69- expect ( error ! ) . toBeUndefined ( ) ;
64+ expect ( error ) . toBeUndefined ( ) ;
7065 } ) ;
7166
7267 test ( "props: list of strings" , async ( ) => {
@@ -79,18 +74,14 @@ describe("props validation", () => {
7974 static template = xml `<div><SubComp /></div>` ;
8075 }
8176
82- const app = new App ( { test : true } ) ;
83- let error : OwlError | undefined ;
84- const mountProm = app
85- . createRoot ( Parent )
86- . mount ( fixture )
87- . catch ( ( e : Error ) => ( error = e ) ) ;
88- await expect ( nextAppError ( app ) ) . resolves . toThrow (
89- "[Owl] Unhandled error. Destroying the root component"
90- ) ;
91- await mountProm ;
92- expect ( error ! ) . toBeDefined ( ) ;
93- expect ( error ! . cause . message ) . toMatch ( "Invalid component props (SubComp)" ) ;
77+ let error : any ;
78+ try {
79+ await mount ( Parent , fixture , { test : true } ) ;
80+ } catch ( e ) {
81+ error = e ;
82+ }
83+ expect ( error ) . toBeDefined ( ) ;
84+ expect ( error . cause . message ) . toMatch ( "Invalid component props (SubComp)" ) ;
9485 } ) ;
9586
9687 test ( "validate props for root component" , async ( ) => {
@@ -132,39 +123,35 @@ describe("props validation", () => {
132123 } ;
133124 ( Parent as any ) . components = { SubComp } ;
134125
126+ let error : any ;
127+
135128 state = { } ;
136- let app = new App ( { test : true } ) ;
137- let error : OwlError | undefined ;
138- let mountProm = app
139- . createRoot ( Parent )
140- . mount ( fixture )
141- . catch ( ( e : Error ) => ( error = e ) ) ;
142- await expect ( nextAppError ( app ) ) . resolves . toThrow (
143- "[Owl] Unhandled error. Destroying the root component"
144- ) ;
145- await mountProm ;
146- expect ( error ! ) . toBeDefined ( ) ;
147- expect ( error ! . cause . message ) . toMatch ( `Invalid component props (SubComp)` ) ;
129+ try {
130+ await mount ( Parent , fixture , { test : true } ) ;
131+ } catch ( e ) {
132+ error = e ;
133+ }
134+ expect ( error ) . toBeDefined ( ) ;
135+ expect ( error . cause . message ) . toMatch ( `Invalid component props (SubComp)` ) ;
136+
148137 error = undefined ;
149138 state = { p : test . ok } ;
150139 try {
151140 await mount ( Parent , fixture , { dev : true } ) ;
152141 } catch ( e ) {
153- error = e as Error ;
142+ error = e ;
154143 }
155- expect ( error ! ) . toBeUndefined ( ) ;
144+ expect ( error ) . toBeUndefined ( ) ;
145+
146+ error = undefined ;
156147 state = { p : test . ko } ;
157- app = new App ( { test : true } ) ;
158- mountProm = app
159- . createRoot ( Parent )
160- . mount ( fixture )
161- . catch ( ( e : Error ) => ( error = e ) ) ;
162- await expect ( nextAppError ( app ) ) . resolves . toThrow (
163- "[Owl] Unhandled error. Destroying the root component"
164- ) ;
165- await mountProm ;
166- expect ( error ! ) . toBeDefined ( ) ;
167- expect ( error ! . cause . message ) . toMatch ( `Invalid component props (SubComp)` ) ;
148+ try {
149+ await mount ( Parent , fixture , { test : true } ) ;
150+ } catch ( e ) {
151+ error = e ;
152+ }
153+ expect ( error ) . toBeDefined ( ) ;
154+ expect ( error . cause . message ) . toMatch ( `Invalid component props (SubComp)` ) ;
168155 }
169156 } ) ;
170157
@@ -197,17 +184,13 @@ describe("props validation", () => {
197184 }
198185 expect ( error ! ) . toBeUndefined ( ) ;
199186 state = { p : 1 } ;
200- const app = new App ( { test : true } ) ;
201- const mountProm = app
202- . createRoot ( Parent )
203- . mount ( fixture )
204- . catch ( ( e : Error ) => ( error = e ) ) ;
205- await expect ( nextAppError ( app ) ) . resolves . toThrow (
206- "[Owl] Unhandled error. Destroying the root component"
207- ) ;
208- await mountProm ;
209- expect ( error ! ) . toBeDefined ( ) ;
210- expect ( error ! . cause . message ) . toMatch ( "Invalid component props (SubComp)" ) ;
187+ try {
188+ await mount ( Parent , fixture , { test : true } ) ;
189+ } catch ( e ) {
190+ error = e ;
191+ }
192+ expect ( error ) . toBeDefined ( ) ;
193+ expect ( error . cause . message ) . toMatch ( "Invalid component props (SubComp)" ) ;
211194 } ) ;
212195
213196 test ( "can validate an optional props" , async ( ) => {
@@ -239,17 +222,13 @@ describe("props validation", () => {
239222 }
240223 expect ( error ! ) . toBeUndefined ( ) ;
241224 state = { p : 1 } ;
242- const app = new App ( { test : true } ) ;
243- const mountProm = app
244- . createRoot ( Parent )
245- . mount ( fixture )
246- . catch ( ( e : Error ) => ( error = e ) ) ;
247- await expect ( nextAppError ( app ) ) . resolves . toThrow (
248- "[Owl] Unhandled error. Destroying the root component"
249- ) ;
250- await mountProm ;
251- expect ( error ! ) . toBeDefined ( ) ;
252- expect ( error ! . cause . message ) . toMatch ( "Invalid component props (SubComp)" ) ;
225+ try {
226+ await mount ( Parent , fixture , { test : true } ) ;
227+ } catch ( e ) {
228+ error = e ;
229+ }
230+ expect ( error ) . toBeDefined ( ) ;
231+ expect ( error . cause . message ) . toMatch ( "Invalid component props (SubComp)" ) ;
253232 } ) ;
254233
255234 test ( "can validate an array with given primitive type" , async ( ) => {
@@ -332,17 +311,13 @@ describe("props validation", () => {
332311 }
333312 expect ( error ! ) . toBeUndefined ( ) ;
334313 state = { p : [ true , 1 ] } ;
335- const app = new App ( { test : true } ) ;
336- const mountProm = app
337- . createRoot ( Parent )
338- . mount ( fixture )
339- . catch ( ( e : Error ) => ( error = e ) ) ;
340- await expect ( nextAppError ( app ) ) . resolves . toThrow (
341- "[Owl] Unhandled error. Destroying the root component"
342- ) ;
343- await mountProm ;
344- expect ( error ! ) . toBeDefined ( ) ;
345- expect ( error ! . cause . message ) . toMatch ( "Invalid component props (SubComp)" ) ;
314+ try {
315+ await mount ( Parent , fixture , { test : true } ) ;
316+ } catch ( e ) {
317+ error = e ;
318+ }
319+ expect ( error ) . toBeDefined ( ) ;
320+ expect ( error . cause . message ) . toMatch ( "Invalid component props (SubComp)" ) ;
346321 } ) ;
347322
348323 test ( "can validate an object with simple shape" , async ( ) => {
0 commit comments