@@ -9,46 +9,71 @@ jest.mock("./screen.class");
99
1010describe ( "Assert" , ( ) => {
1111 it ( "isVisible should not throw if a match is found." , async ( ) => {
12- Screen . prototype . findOnScreen = jest . fn ( ( ) => Promise . resolve ( new Region ( 0 , 0 , 100 , 100 ) ) ) ;
12+ // GIVEN
13+ Screen . prototype . find = jest . fn ( ( ) => Promise . resolve ( new Region ( 0 , 0 , 100 , 100 ) ) ) ;
1314 const screenMock = new Screen ( new VisionAdapter ( ) ) ;
1415 const SUT = new Assert ( screenMock ) ;
16+ const needle = "foo" ;
1517
16- await expect ( SUT . isVisible ( "foo" ) ) . resolves . not . toThrowError ( ) ;
18+ // WHEN
19+
20+ // THEN
21+ await expect ( SUT . isVisible ( needle ) ) . resolves . not . toThrowError ( ) ;
1722 } ) ;
1823
1924 it ( "isVisible should throw if a match is found." , async ( ) => {
20- Screen . prototype . findOnScreen = jest . fn ( ( ) => Promise . reject ( "foo" ) ) ;
25+ // GIVEN
26+ Screen . prototype . find = jest . fn ( ( ) => Promise . reject ( "foo" ) ) ;
2127 const screenMock = new Screen ( new VisionAdapter ( ) ) ;
2228 const SUT = new Assert ( screenMock ) ;
29+ const needle = "foo" ;
30+
31+ // WHEN
2332
24- await expect ( SUT . isVisible ( "foo" ) ) . rejects . toThrowError ( "Element not found" ) ;
33+ // THEN
34+ await expect ( SUT . isVisible ( needle ) ) . rejects . toThrowError ( `Element '${ needle } ' not found` ) ;
2535 } ) ;
2636
2737 it ( "isVisible should throw if a match is found." , async ( ) => {
28- Screen . prototype . findOnScreen = jest . fn ( ( ) => Promise . reject ( "foo" ) ) ;
38+ // GIVEN
39+ Screen . prototype . find = jest . fn ( ( ) => Promise . reject ( "foo" ) ) ;
2940 const screenMock = new Screen ( new VisionAdapter ( ) ) ;
3041 const SUT = new Assert ( screenMock ) ;
3142 const searchRegion = new Region ( 10 , 10 , 10 , 10 ) ;
43+ const needle = "foo" ;
44+
45+ // WHEN
3246
47+ // THEN
3348 await expect ( SUT
34- . isVisible ( "foo" , searchRegion ) )
35- . rejects . toThrowError ( `Element not found in region ${ searchRegion . toString ( ) } `
49+ . isVisible ( needle , searchRegion ) )
50+ . rejects . toThrowError ( `Element ' ${ needle } ' not found in region ${ searchRegion . toString ( ) } `
3651 ) ;
3752 } ) ;
3853
3954 it ( "isNotVisible should throw if a match is found." , async ( ) => {
40- Screen . prototype . findOnScreen = jest . fn ( ( ) => Promise . resolve ( new Region ( 0 , 0 , 100 , 100 ) ) ) ;
55+ // GIVEN
56+ Screen . prototype . find = jest . fn ( ( ) => Promise . resolve ( new Region ( 0 , 0 , 100 , 100 ) ) ) ;
4157 const screenMock = new Screen ( new VisionAdapter ( ) ) ;
4258 const SUT = new Assert ( screenMock ) ;
59+ const needle = "foo" ;
4360
44- await expect ( SUT . notVisible ( "foo" ) ) . rejects . toThrowError ( "Element visible" ) ;
61+ // WHEN
62+
63+ // THEN
64+ await expect ( SUT . notVisible ( needle ) ) . rejects . toThrowError ( `'${ needle } ' is visible` ) ;
4565 } ) ;
4666
4767 it ( "isVisible should throw if a match is found." , async ( ) => {
48- Screen . prototype . findOnScreen = jest . fn ( ( ) => Promise . reject ( "foo" ) ) ;
68+ // GIVEN
69+ Screen . prototype . find = jest . fn ( ( ) => Promise . reject ( "foo" ) ) ;
4970 const screenMock = new Screen ( new VisionAdapter ( ) ) ;
5071 const SUT = new Assert ( screenMock ) ;
72+ const needle = "foo" ;
73+
74+ // WHEN
5175
52- await expect ( SUT . notVisible ( "foo" ) ) . resolves . not . toThrowError ( ) ;
76+ // THEN
77+ await expect ( SUT . notVisible ( needle ) ) . resolves . not . toThrowError ( ) ;
5378 } ) ;
5479} ) ;
0 commit comments