@@ -2,7 +2,7 @@ import { UmbContextProvider } from '../provide/context-provider.js';
2
2
import { UmbContextToken } from '../token/context-token.js' ;
3
3
import type { UmbContextMinimal } from '../types.js' ;
4
4
import { UmbContextConsumer } from './context-consumer.js' ;
5
- import type { UmbContextRequestEventImplementation } from './context-request.event.js' ;
5
+ import { UmbContextRequestEventImplementation } from './context-request.event.js' ;
6
6
import { UMB_CONTEXT_REQUEST_EVENT_TYPE } from './context-request.event.js' ;
7
7
import { assert , expect , oneEvent } from '@open-wc/testing' ;
8
8
@@ -266,7 +266,7 @@ describe('UmbContextConsumer', () => {
266
266
localConsumer . hostConnected ( ) ;
267
267
} ) ;
268
268
269
- it ( 'does not respond to a non existing api alias' , ( done ) => {
269
+ it ( 'does not respond to a non existing api alias' , async ( ) => {
270
270
const provider = new UmbContextProvider (
271
271
document . body ,
272
272
testContextAliasAndApiAlias ,
@@ -277,21 +277,19 @@ describe('UmbContextConsumer', () => {
277
277
let callbackCount = 0 ;
278
278
279
279
const localConsumer = new UmbContextConsumer ( element , testContextAliasAndNotExistingApiAlias , ( context ) => {
280
- callbackCount ++ ;
281
- if ( callbackCount === 1 ) {
282
- expect ( context ) . to . be . undefined ;
283
- done ( ) ;
284
- } else {
285
- assert . fail ( 'Callback should not be called more than once' ) ;
286
- }
280
+ assert . fail ( 'Callback should not be called more than once' ) ;
287
281
} ) ;
282
+ const requestEvent = oneEvent ( localConsumer . getHostElement ( ) , UMB_CONTEXT_REQUEST_EVENT_TYPE ) ;
288
283
localConsumer . hostConnected ( ) ;
289
284
285
+ await requestEvent ;
286
+ await Promise . resolve ( ) ;
287
+
290
288
// Delayed check to make sure the callback is not called.
291
- Promise . resolve ( ) . then ( ( ) => {
292
- localConsumer . hostDisconnected ( ) ;
293
- provider . hostDisconnected ( ) ;
294
- } ) ;
289
+
290
+ expect ( callbackCount ) . to . equal ( 0 , 'Callback should never have been called' ) ;
291
+ localConsumer . hostDisconnected ( ) ;
292
+ provider . hostDisconnected ( ) ;
295
293
} ) ;
296
294
} ) ;
297
295
@@ -368,7 +366,7 @@ describe('UmbContextConsumer', () => {
368
366
localConsumer . hostConnected ( ) ;
369
367
} ) ;
370
368
371
- it ( 'disapproving discriminator does not fire callback' , ( done ) => {
369
+ it ( 'disapproving discriminator does not fire callback' , async ( ) => {
372
370
const provider = new UmbContextProvider ( document . body , testContextAlias , new UmbTestContextConsumerClass ( ) ) ;
373
371
provider . hostConnected ( ) ;
374
372
@@ -379,24 +377,21 @@ describe('UmbContextConsumer', () => {
379
377
new UmbContextToken ( testContextAlias , undefined , badDiscriminator ) ,
380
378
( _instance ) => {
381
379
callbackCount ++ ;
382
- if ( callbackCount === 1 ) {
383
- expect ( _instance ) . to . be . undefined ;
384
- done ( ) ;
385
- } else {
386
- assert . fail ( 'Callback should not be called more than once' ) ;
387
- }
380
+ assert . fail ( 'Callback should not be called more than once' ) ;
388
381
} ,
389
382
) ;
383
+ const requestEvent = oneEvent ( localConsumer . getHostElement ( ) , UMB_CONTEXT_REQUEST_EVENT_TYPE ) ;
390
384
localConsumer . hostConnected ( ) ;
391
385
392
386
// Wait for to ensure the above request didn't succeed:
393
- Promise . resolve ( ) . then ( ( ) => {
394
- localConsumer . hostDisconnected ( ) ;
395
- provider . hostDisconnected ( ) ;
396
- } ) ;
387
+ await requestEvent ;
388
+ await Promise . resolve ( ) ;
389
+ expect ( callbackCount ) . to . equal ( 0 , 'Callback should never have been called' ) ;
390
+ localConsumer . hostDisconnected ( ) ;
391
+ provider . hostDisconnected ( ) ;
397
392
} ) ;
398
393
399
- it ( 'context api of same context alias will prevent request from propagating' , ( done ) => {
394
+ it ( 'context api of same context alias will prevent request from propagating' , async ( ) => {
400
395
const provider = new UmbContextProvider ( document . body , testContextAlias , new UmbTestContextConsumerClass ( ) ) ;
401
396
provider . hostConnected ( ) ;
402
397
@@ -414,19 +409,18 @@ describe('UmbContextConsumer', () => {
414
409
new UmbContextToken ( testContextAlias , undefined , discriminator ) ,
415
410
( _instance ) => {
416
411
callbackCount ++ ;
417
- if ( callbackCount === 1 ) {
418
- expect ( _instance ) . to . be . undefined ;
419
- done ( ) ;
420
- }
421
412
} ,
422
413
) ;
414
+ const requestEvent = oneEvent ( localConsumer . getHostElement ( ) , UMB_CONTEXT_REQUEST_EVENT_TYPE ) ;
423
415
localConsumer . hostConnected ( ) ;
424
416
417
+ await requestEvent ;
418
+ await Promise . resolve ( ) ;
425
419
// Wait for to ensure the above request didn't succeed:
426
- Promise . resolve ( ) . then ( ( ) => {
427
- localConsumer . hostDisconnected ( ) ;
428
- provider . hostDisconnected ( ) ;
429
- } ) ;
420
+
421
+ expect ( callbackCount ) . to . equal ( 0 , 'Callback should never have been called' ) ;
422
+ localConsumer . hostDisconnected ( ) ;
423
+ provider . hostDisconnected ( ) ;
430
424
} ) ;
431
425
432
426
it ( 'context api of same context alias will NOT prevent request from propagating when set to passContextAliasMatches' , ( done ) => {
0 commit comments