File tree 1 file changed +26
-0
lines changed
apps/example-app/src/app/examples
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { Component } from '@angular/core' ;
1
2
import { render , screen } from '@testing-library/angular' ;
2
3
import userEvent from '@testing-library/user-event' ;
3
4
4
5
import { SpoilerDirective } from './08-directive' ;
5
6
7
+ test ( 'it is possible to test directives with container component' , async ( ) => {
8
+ @Component ( {
9
+ template : `<div appSpoiler data-testid="dir"></div>` ,
10
+ imports : [ SpoilerDirective ] ,
11
+ standalone : true ,
12
+ } )
13
+ class FixtureComponent { }
14
+
15
+ const user = userEvent . setup ( ) ;
16
+ await render ( FixtureComponent ) ;
17
+
18
+ const directive = screen . getByTestId ( 'dir' ) ;
19
+
20
+ expect ( screen . queryByText ( 'I am visible now...' ) ) . not . toBeInTheDocument ( ) ;
21
+ expect ( screen . getByText ( 'SPOILER' ) ) . toBeInTheDocument ( ) ;
22
+
23
+ await user . hover ( directive ) ;
24
+ expect ( screen . queryByText ( 'SPOILER' ) ) . not . toBeInTheDocument ( ) ;
25
+ expect ( screen . getByText ( 'I am visible now...' ) ) . toBeInTheDocument ( ) ;
26
+
27
+ await user . unhover ( directive ) ;
28
+ expect ( screen . getByText ( 'SPOILER' ) ) . toBeInTheDocument ( ) ;
29
+ expect ( screen . queryByText ( 'I am visible now...' ) ) . not . toBeInTheDocument ( ) ;
30
+ } ) ;
31
+
6
32
test ( 'it is possible to test directives' , async ( ) => {
7
33
const user = userEvent . setup ( ) ;
8
34
You can’t perform that action at this time.
0 commit comments