@@ -8,6 +8,10 @@ const { View, Method } = require('./init');
88
99
1010const view = new View ( { file : 'test.qml' , silent : true } ) ;
11+ const loadPromise = Promise . race ( [
12+ new Promise ( ( res ) => { setTimeout ( ( ) => res ( false ) , 5000 ) ; } ) ,
13+ new Promise ( ( res ) => view . on ( 'load' , ( ) => res ( true ) ) ) ,
14+ ] ) ;
1115view . on ( 'error' , ( ) => { } ) ;
1216
1317const opts = { view, name : 'obj1' , key : 'method1' } ;
@@ -26,6 +30,9 @@ const tested = describe('Method', () => {
2630 } ) ;
2731
2832 it ( 'calls QML method1' , async ( ) => {
33+ const loaded = await loadPromise ;
34+ assert . strictEqual ( loaded , true ) ;
35+
2936 const method1 = new Method ( opts ) ;
3037 const called = await new Promise ( ( res ) => {
3138 view . on ( 'm1c' , ( ) => res ( true ) ) ;
@@ -35,6 +42,9 @@ const tested = describe('Method', () => {
3542 } ) ;
3643
3744 it ( 'calls QML method2' , async ( ) => {
45+ const loaded = await loadPromise ;
46+ assert . strictEqual ( loaded , true ) ;
47+
3848 const method2 = new Method ( { ...opts , key : 'method2' } ) ;
3949 const called = await new Promise ( ( res ) => {
4050 view . on ( 'm2c' , ( ) => res ( true ) ) ;
@@ -43,12 +53,18 @@ const tested = describe('Method', () => {
4353 assert . strictEqual ( called , true ) ;
4454 } ) ;
4555
46- it ( 'calls non-existent object\'s method, and gets null' , ( ) => {
56+ it ( 'calls non-existent object\'s method, and gets null' , async ( ) => {
57+ const loaded = await loadPromise ;
58+ assert . strictEqual ( loaded , true ) ;
59+
4760 const method = new Method ( { ...opts , name : 'awdaldaklwd23' } ) ;
4861 assert . strictEqual ( method ( ) , null ) ;
4962 } ) ;
5063
51- it ( 'calls non-existent method, and gets null' , ( ) => {
64+ it ( 'calls non-existent method, and gets null' , async ( ) => {
65+ const loaded = await loadPromise ;
66+ assert . strictEqual ( loaded , true ) ;
67+
5268 const method = new Method ( { ...opts , key : 'awdaldaklwd23' } ) ;
5369 assert . strictEqual ( method ( ) , null ) ;
5470 } ) ;
0 commit comments