1- import { defineCE , expect , fixture , html , nextFrame , oneEvent , runConstructor } from '@brightspace-ui/testing' ;
1+ import { defineCE , expect , fixture , html , oneEvent , runConstructor , waitUntil } from '@brightspace-ui/testing' ;
22import { LitElement , nothing } from 'lit' ;
33import { states } from '../expand-collapse-content.js' ;
44
@@ -63,7 +63,7 @@ describe('d2l-expand-collapse-content', () => {
6363 describe ( 'events' , ( ) => {
6464
6565 [ true , false ] . forEach ( expand => {
66- const event = ` d2l-expand-collapse-content-${ expand ? 'expand' : 'collapse' } ` ;
66+ const event = expand ? ' d2l-expand-collapse-content-expand' : 'd2l-expand- collapse-content-collapse' ;
6767
6868 async function changeState ( content ) {
6969 setTimeout ( ( ) => content . expanded = expand ) ;
@@ -87,14 +87,14 @@ describe('d2l-expand-collapse-content', () => {
8787 it ( `should fire ${ event } event with transition states` , async ( ) => {
8888 const content = ( await fixture ( `<${ tagName } ${ expand ? '' : ' expanded' } transitions></${ tagName } >` ) ) . shadowRoot . querySelector ( 'd2l-expand-collapse-content' ) ;
8989
90+
9091 const e = await changeState ( content ) ;
92+
9193 expect ( content . _state ) . to . equal ( expand ? states . PREEXPANDING : states . PRECOLLAPSING ) ;
9294
93- await content . updateComplete ;
94- await nextFrame ( ) ;
95- await nextFrame ( ) ;
95+ const transitionState = ( expand ? states . EXPANDING : states . COLLAPSING ) ;
96+ await waitUntil ( ( ) => content . _state === transitionState , `never reached state: ${ transitionState } ` ) ; ;
9697
97- expect ( content . _state ) . to . equal ( expand ? states . EXPANDING : states . COLLAPSING ) ;
9898 await e . detail [ `${ expand ? 'expand' : 'collapse' } Complete` ] ;
9999 expect ( content . _state ) . to . equal ( expand ? states . EXPANDED : states . COLLAPSED ) ;
100100 } ) ;
0 commit comments