@@ -2,37 +2,44 @@ import {AssertClass} from "./assert.class";
2
2
import { Region } from "./region.class" ;
3
3
import { ScreenClass } from "./screen.class" ;
4
4
import providerRegistry from "./provider/provider-registry.class" ;
5
- import { imageResource } from "../index" ;
5
+ import { Image } from "../index" ;
6
+ import { mockPartial } from "sneer" ;
6
7
7
8
jest . mock ( 'jimp' , ( ) => {
8
9
} ) ;
9
10
jest . mock ( "./screen.class" ) ;
10
11
12
+ const needleId = "needleId" ;
13
+
11
14
describe ( "Assert" , ( ) => {
12
15
it ( "isVisible should not throw if a match is found." , async ( ) => {
13
16
// GIVEN
14
17
ScreenClass . prototype . find = jest . fn ( ( ) => Promise . resolve ( new Region ( 0 , 0 , 100 , 100 ) ) ) ;
15
18
const screenMock = new ScreenClass ( providerRegistry ) ;
16
19
const SUT = new AssertClass ( screenMock ) ;
17
- const needle = "foo" ;
20
+ const needle = mockPartial < Image > ( {
21
+ id : needleId
22
+ } ) ;
18
23
19
24
// WHEN
20
25
21
26
// THEN
22
- await expect ( SUT . isVisible ( imageResource ( needle ) ) ) . resolves . not . toThrowError ( ) ;
27
+ await expect ( SUT . isVisible ( needle ) ) . resolves . not . toThrowError ( ) ;
23
28
} ) ;
24
29
25
30
it ( "isVisible should throw if a match is found." , async ( ) => {
26
31
// GIVEN
27
32
ScreenClass . prototype . find = jest . fn ( ( ) => Promise . reject ( "foo" ) ) ;
28
33
const screenMock = new ScreenClass ( providerRegistry ) ;
29
34
const SUT = new AssertClass ( screenMock ) ;
30
- const needle = "foo" ;
35
+ const needle = mockPartial < Image > ( {
36
+ id : needleId
37
+ } ) ;
31
38
32
39
// WHEN
33
40
34
41
// THEN
35
- await expect ( SUT . isVisible ( imageResource ( needle ) ) ) . rejects . toThrowError ( `Element '${ needle } ' not found` ) ;
42
+ await expect ( SUT . isVisible ( needle ) ) . rejects . toThrowError ( `Element '${ needle . id } ' not found` ) ;
36
43
} ) ;
37
44
38
45
it ( "isVisible should throw if a match is found." , async ( ) => {
@@ -41,14 +48,16 @@ describe("Assert", () => {
41
48
const screenMock = new ScreenClass ( providerRegistry ) ;
42
49
const SUT = new AssertClass ( screenMock ) ;
43
50
const searchRegion = new Region ( 10 , 10 , 10 , 10 ) ;
44
- const needle = "foo" ;
51
+ const needle = mockPartial < Image > ( {
52
+ id : needleId
53
+ } ) ;
45
54
46
55
// WHEN
47
56
48
57
// THEN
49
58
await expect ( SUT
50
- . isVisible ( imageResource ( needle ) , searchRegion ) )
51
- . rejects . toThrowError ( `Element '${ needle } ' not found in region ${ searchRegion . toString ( ) } `
59
+ . isVisible ( needle , searchRegion ) )
60
+ . rejects . toThrowError ( `Element '${ needle . id } ' not found in region ${ searchRegion . toString ( ) } `
52
61
) ;
53
62
} ) ;
54
63
@@ -57,24 +66,28 @@ describe("Assert", () => {
57
66
ScreenClass . prototype . find = jest . fn ( ( ) => Promise . resolve ( new Region ( 0 , 0 , 100 , 100 ) ) ) ;
58
67
const screenMock = new ScreenClass ( providerRegistry ) ;
59
68
const SUT = new AssertClass ( screenMock ) ;
60
- const needle = "foo" ;
69
+ const needle = mockPartial < Image > ( {
70
+ id : needleId
71
+ } ) ;
61
72
62
73
// WHEN
63
74
64
75
// THEN
65
- await expect ( SUT . notVisible ( imageResource ( needle ) ) ) . rejects . toThrowError ( `'${ needle } ' is visible` ) ;
76
+ await expect ( SUT . notVisible ( needle ) ) . rejects . toThrowError ( `'${ needle . id } ' is visible` ) ;
66
77
} ) ;
67
78
68
79
it ( "isVisible should throw if a match is found." , async ( ) => {
69
80
// GIVEN
70
81
ScreenClass . prototype . find = jest . fn ( ( ) => Promise . reject ( "foo" ) ) ;
71
82
const screenMock = new ScreenClass ( providerRegistry ) ;
72
83
const SUT = new AssertClass ( screenMock ) ;
73
- const needle = "foo" ;
84
+ const needle = mockPartial < Image > ( {
85
+ id : needleId
86
+ } ) ;
74
87
75
88
// WHEN
76
89
77
90
// THEN
78
- await expect ( SUT . notVisible ( imageResource ( needle ) ) ) . resolves . not . toThrowError ( ) ;
91
+ await expect ( SUT . notVisible ( needle ) ) . resolves . not . toThrowError ( ) ;
79
92
} ) ;
80
93
} ) ;
0 commit comments