99
1010'use strict' ;
1111
12- import { Application , Controller } from 'stimulus' ;
12+ import { Application , Controller } from '@hotwired/ stimulus' ;
1313import { getByTestId , waitFor } from '@testing-library/dom' ;
1414import { clearDOM , mountDOM } from '@symfony/stimulus-testing' ;
1515import FormCollectionController from '../src/controller' ;
@@ -30,29 +30,35 @@ const startStimulus = () => {
3030 const application = Application . start ( ) ;
3131 application . register ( 'check' , CheckController ) ;
3232 application . register ( 'formCollection' , FormCollectionController ) ;
33+
34+ return application ;
3335} ;
3436
3537describe ( 'FormCollectionController' , ( ) => {
36- let container : HTMLElement ;
37-
38- beforeEach ( ( ) => {
39- container = mountDOM ( `
40- <div class="container" data-controller="check formCollection" data-testid="container">
41-
42- </div>
43- ` ) ;
44- } ) ;
38+ let application ;
4539
4640 afterEach ( ( ) => {
4741 clearDOM ( ) ;
42+ application . stop ( ) ;
4843 } ) ;
4944
5045 it ( 'events' , async ( ) => {
51- expect ( getByTestId ( container , 'container' ) ) . not . toHaveClass ( 'connected' ) ;
46+ const container = mountDOM ( `
47+ <div
48+ data-testid="container"
49+ data-controller="check formCollection"
50+ class="container">
51+ </div>
52+ ` ) ;
53+
5254 expect ( getByTestId ( container , 'container' ) ) . not . toHaveClass ( 'pre-connected' ) ;
55+ expect ( getByTestId ( container , 'container' ) ) . not . toHaveClass ( 'connected' ) ;
56+
57+ application = startStimulus ( ) ;
5358
54- startStimulus ( ) ;
55- await waitFor ( ( ) => expect ( getByTestId ( container , 'container' ) ) . toHaveClass ( 'connected' ) ) ;
56- await waitFor ( ( ) => expect ( getByTestId ( container , 'container' ) ) . toHaveClass ( 'pre-connected' ) ) ;
59+ await waitFor ( ( ) => {
60+ expect ( getByTestId ( container , 'container' ) ) . toHaveClass ( 'pre-connected' )
61+ expect ( getByTestId ( container , 'container' ) ) . toHaveClass ( 'connected' )
62+ } ) ;
5763 } ) ;
5864} ) ;
0 commit comments