Skip to content

Commit 25b1e2a

Browse files
committed
(#329) Adjusted tests
1 parent 419cba1 commit 25b1e2a

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

lib/assert.class.spec.ts

+25-12
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,44 @@ import {AssertClass} from "./assert.class";
22
import {Region} from "./region.class";
33
import {ScreenClass} from "./screen.class";
44
import providerRegistry from "./provider/provider-registry.class";
5-
import {imageResource} from "../index";
5+
import {Image} from "../index";
6+
import {mockPartial} from "sneer";
67

78
jest.mock('jimp', () => {
89
});
910
jest.mock("./screen.class");
1011

12+
const needleId = "needleId";
13+
1114
describe("Assert", () => {
1215
it("isVisible should not throw if a match is found.", async () => {
1316
// GIVEN
1417
ScreenClass.prototype.find = jest.fn(() => Promise.resolve(new Region(0, 0, 100, 100)));
1518
const screenMock = new ScreenClass(providerRegistry);
1619
const SUT = new AssertClass(screenMock);
17-
const needle = "foo";
20+
const needle = mockPartial<Image>({
21+
id: needleId
22+
});
1823

1924
// WHEN
2025

2126
// THEN
22-
await expect(SUT.isVisible(imageResource(needle))).resolves.not.toThrowError();
27+
await expect(SUT.isVisible(needle)).resolves.not.toThrowError();
2328
});
2429

2530
it("isVisible should throw if a match is found.", async () => {
2631
// GIVEN
2732
ScreenClass.prototype.find = jest.fn(() => Promise.reject("foo"));
2833
const screenMock = new ScreenClass(providerRegistry);
2934
const SUT = new AssertClass(screenMock);
30-
const needle = "foo";
35+
const needle = mockPartial<Image>({
36+
id: needleId
37+
});
3138

3239
// WHEN
3340

3441
// 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`);
3643
});
3744

3845
it("isVisible should throw if a match is found.", async () => {
@@ -41,14 +48,16 @@ describe("Assert", () => {
4148
const screenMock = new ScreenClass(providerRegistry);
4249
const SUT = new AssertClass(screenMock);
4350
const searchRegion = new Region(10, 10, 10, 10);
44-
const needle = "foo";
51+
const needle = mockPartial<Image>({
52+
id: needleId
53+
});
4554

4655
// WHEN
4756

4857
// THEN
4958
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()}`
5261
);
5362
});
5463

@@ -57,24 +66,28 @@ describe("Assert", () => {
5766
ScreenClass.prototype.find = jest.fn(() => Promise.resolve(new Region(0, 0, 100, 100)));
5867
const screenMock = new ScreenClass(providerRegistry);
5968
const SUT = new AssertClass(screenMock);
60-
const needle = "foo";
69+
const needle = mockPartial<Image>({
70+
id: needleId
71+
});
6172

6273
// WHEN
6374

6475
// 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`);
6677
});
6778

6879
it("isVisible should throw if a match is found.", async () => {
6980
// GIVEN
7081
ScreenClass.prototype.find = jest.fn(() => Promise.reject("foo"));
7182
const screenMock = new ScreenClass(providerRegistry);
7283
const SUT = new AssertClass(screenMock);
73-
const needle = "foo";
84+
const needle = mockPartial<Image>({
85+
id: needleId
86+
});
7487

7588
// WHEN
7689

7790
// THEN
78-
await expect(SUT.notVisible(imageResource(needle))).resolves.not.toThrowError();
91+
await expect(SUT.notVisible(needle)).resolves.not.toThrowError();
7992
});
8093
});

0 commit comments

Comments
 (0)