expect-webdriverio 5.3.3 → 5.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{tsconfig.tsbuildinfo → tsconfig.build.tsbuildinfo} +1 -1
- package/package.json +2 -2
- package/types/expect-webdriverio.d.ts +27 -38
- package/types/standalone.d.ts +0 -2
- package/lib/test/__fixtures__/utils.js +0 -19
- package/lib/test/index.test.js +0 -8
- package/lib/test/matchers/beMatchers.test.js +0 -109
- package/lib/test/matchers/browser/toHaveClipboardText.test.js +0 -21
- package/lib/test/matchers/browserMatchers.test.js +0 -102
- package/lib/test/matchers/element/toBeDisabled.test.js +0 -121
- package/lib/test/matchers/element/toHaveAttribute.test.js +0 -131
- package/lib/test/matchers/element/toHaveChildren.test.js +0 -62
- package/lib/test/matchers/element/toHaveComputedLabel.test.js +0 -284
- package/lib/test/matchers/element/toHaveComputedRole.test.js +0 -284
- package/lib/test/matchers/element/toHaveElementClass.test.js +0 -125
- package/lib/test/matchers/element/toHaveElementProperty.test.js +0 -111
- package/lib/test/matchers/element/toHaveHTML.test.js +0 -291
- package/lib/test/matchers/element/toHaveHeight.test.js +0 -171
- package/lib/test/matchers/element/toHaveHref.test.js +0 -54
- package/lib/test/matchers/element/toHaveId.test.js +0 -54
- package/lib/test/matchers/element/toHaveSize.test.js +0 -109
- package/lib/test/matchers/element/toHaveStyle.test.js +0 -199
- package/lib/test/matchers/element/toHaveText.test.js +0 -333
- package/lib/test/matchers/element/toHaveValue.test.js +0 -81
- package/lib/test/matchers/element/toHaveWidth.test.js +0 -171
- package/lib/test/matchers/elements/toBeElementsArrayOfSize.test.js +0 -141
- package/lib/test/matchers/mock/toBeRequested.test.js +0 -73
- package/lib/test/matchers/mock/toBeRequestedTimes.test.js +0 -108
- package/lib/test/matchers/mock/toBeRequestedWith.test.js +0 -343
- package/lib/test/matchers.test.js +0 -54
- package/lib/test/snapshot.test.js +0 -53
- package/lib/test/softAssertions.test.js +0 -332
- package/lib/test/util/elementsUtil.test.js +0 -18
- package/lib/test/util/formatMessage.test.js +0 -96
- package/lib/test/util/refetchElements.test.js +0 -19
- package/lib/test/utils.test.js +0 -117
- /package/lib/{src/constants.js → constants.js} +0 -0
- /package/lib/{src/index.js → index.js} +0 -0
- /package/lib/{src/jasmineUtils.js → jasmineUtils.js} +0 -0
- /package/lib/{src/matchers → matchers}/browser/toHaveClipboardText.js +0 -0
- /package/lib/{src/matchers → matchers}/browser/toHaveTitle.js +0 -0
- /package/lib/{src/matchers → matchers}/browser/toHaveUrl.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeClickable.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeDisabled.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeDisplayed.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeDisplayedInViewport.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeEnabled.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeExisting.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeFocused.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeSelected.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveAttribute.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveChildren.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveClass.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveComputedLabel.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveComputedRole.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveElementProperty.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveHTML.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveHeight.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveHref.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveId.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveSize.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveStyle.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveText.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveValue.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveWidth.js +0 -0
- /package/lib/{src/matchers → matchers}/elements/toBeElementsArrayOfSize.js +0 -0
- /package/lib/{src/matchers → matchers}/mock/toBeRequested.js +0 -0
- /package/lib/{src/matchers → matchers}/mock/toBeRequestedTimes.js +0 -0
- /package/lib/{src/matchers → matchers}/mock/toBeRequestedWith.js +0 -0
- /package/lib/{src/matchers → matchers}/snapshot.js +0 -0
- /package/lib/{src/matchers.js → matchers.js} +0 -0
- /package/lib/{src/snapshot.js → snapshot.js} +0 -0
- /package/lib/{src/softAssert.js → softAssert.js} +0 -0
- /package/lib/{src/softAssertService.js → softAssertService.js} +0 -0
- /package/lib/{src/softExpect.js → softExpect.js} +0 -0
- /package/lib/{src/types.js → types.js} +0 -0
- /package/lib/{src/util → util}/elementsUtil.js +0 -0
- /package/lib/{src/util → util}/executeCommand.js +0 -0
- /package/lib/{src/util → util}/formatMessage.js +0 -0
- /package/lib/{src/util → util}/refetchElements.js +0 -0
- /package/lib/{src/utils.js → utils.js} +0 -0
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { vi, test, describe, expect } from 'vitest';
|
|
2
|
-
import { $ } from '@wdio/globals';
|
|
3
|
-
import { getExpectMessage, getReceived } from '../../__fixtures__/utils.js';
|
|
4
|
-
import { toHaveWidth } from '../../../src/matchers/element/toHaveWidth.js';
|
|
5
|
-
vi.mock('@wdio/globals');
|
|
6
|
-
describe('toHaveWidth', () => {
|
|
7
|
-
test('wait for success', async () => {
|
|
8
|
-
const el = await $('sel');
|
|
9
|
-
el._attempts = 2;
|
|
10
|
-
el._size = function (property) {
|
|
11
|
-
if (this._attempts > 0) {
|
|
12
|
-
this._attempts--;
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
if (property === 'width') {
|
|
16
|
-
return 50;
|
|
17
|
-
}
|
|
18
|
-
if (property === 'height') {
|
|
19
|
-
return 32;
|
|
20
|
-
}
|
|
21
|
-
return { width: 50, height: 32 };
|
|
22
|
-
};
|
|
23
|
-
const beforeAssertion = vi.fn();
|
|
24
|
-
const afterAssertion = vi.fn();
|
|
25
|
-
const result = await toHaveWidth.call({}, el, 50, { beforeAssertion, afterAssertion });
|
|
26
|
-
expect(result.pass).toBe(true);
|
|
27
|
-
expect(el._attempts).toBe(0);
|
|
28
|
-
expect(beforeAssertion).toBeCalledWith({
|
|
29
|
-
matcherName: 'toHaveWidth',
|
|
30
|
-
expectedValue: 50,
|
|
31
|
-
options: { beforeAssertion, afterAssertion }
|
|
32
|
-
});
|
|
33
|
-
expect(afterAssertion).toBeCalledWith({
|
|
34
|
-
matcherName: 'toHaveWidth',
|
|
35
|
-
expectedValue: 50,
|
|
36
|
-
options: { beforeAssertion, afterAssertion },
|
|
37
|
-
result
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
test('wait but failure', async () => {
|
|
41
|
-
const el = await $('sel');
|
|
42
|
-
el._size = function () {
|
|
43
|
-
throw new Error('some error');
|
|
44
|
-
};
|
|
45
|
-
await expect(() => toHaveWidth.call({}, el, 10, {}))
|
|
46
|
-
.rejects.toThrow('some error');
|
|
47
|
-
});
|
|
48
|
-
test('success on the first attempt', async () => {
|
|
49
|
-
const el = await $('sel');
|
|
50
|
-
el._attempts = 0;
|
|
51
|
-
el._size = function (property) {
|
|
52
|
-
this._attempts++;
|
|
53
|
-
if (property === 'width') {
|
|
54
|
-
return 50;
|
|
55
|
-
}
|
|
56
|
-
if (property === 'height') {
|
|
57
|
-
return 32;
|
|
58
|
-
}
|
|
59
|
-
return { width: 50, height: 32 };
|
|
60
|
-
};
|
|
61
|
-
const result = await toHaveWidth.call({}, el, 50, {});
|
|
62
|
-
expect(result.message()).toEqual('Expect $(`sel`) to have width\n\nExpected: 50\nReceived: serializes to the same string');
|
|
63
|
-
expect(result.pass).toBe(true);
|
|
64
|
-
expect(el._attempts).toBe(1);
|
|
65
|
-
});
|
|
66
|
-
test('no wait - failure', async () => {
|
|
67
|
-
const el = await $('sel');
|
|
68
|
-
el._attempts = 0;
|
|
69
|
-
el._size = function (property) {
|
|
70
|
-
this._attempts++;
|
|
71
|
-
if (property === 'width') {
|
|
72
|
-
return 50;
|
|
73
|
-
}
|
|
74
|
-
if (property === 'height') {
|
|
75
|
-
return 32;
|
|
76
|
-
}
|
|
77
|
-
return { width: 50, height: 32 };
|
|
78
|
-
};
|
|
79
|
-
const result = await toHaveWidth.call({}, el, 10, { wait: 0 });
|
|
80
|
-
expect(result.message()).toEqual('Expect $(`sel`) to have width\n\nExpected: 10\nReceived: 50');
|
|
81
|
-
expect(result.pass).toBe(false);
|
|
82
|
-
expect(el._attempts).toBe(1);
|
|
83
|
-
});
|
|
84
|
-
test('no wait - success', async () => {
|
|
85
|
-
const el = await $('sel');
|
|
86
|
-
el._attempts = 0;
|
|
87
|
-
el._size = function (property) {
|
|
88
|
-
this._attempts++;
|
|
89
|
-
if (property === 'width') {
|
|
90
|
-
return 50;
|
|
91
|
-
}
|
|
92
|
-
if (property === 'height') {
|
|
93
|
-
return 32;
|
|
94
|
-
}
|
|
95
|
-
return { width: 50, height: 32 };
|
|
96
|
-
};
|
|
97
|
-
const result = await toHaveWidth.call({}, el, 50, { wait: 0 });
|
|
98
|
-
expect(result.pass).toBe(true);
|
|
99
|
-
expect(el._attempts).toBe(1);
|
|
100
|
-
});
|
|
101
|
-
test('gte and lte', async () => {
|
|
102
|
-
const el = await $('sel');
|
|
103
|
-
el._attempts = 0;
|
|
104
|
-
el._size = function (property) {
|
|
105
|
-
this._attempts++;
|
|
106
|
-
if (property === 'width') {
|
|
107
|
-
return 50;
|
|
108
|
-
}
|
|
109
|
-
if (property === 'height') {
|
|
110
|
-
return 32;
|
|
111
|
-
}
|
|
112
|
-
return { width: 50, height: 32 };
|
|
113
|
-
};
|
|
114
|
-
const result = await toHaveWidth.call({}, el, { gte: 49, lte: 51 }, { wait: 0 });
|
|
115
|
-
expect(result.message()).toEqual('Expect $(`sel`) to have width\n\nExpected: ">= 49 && <= 51"\nReceived: 50');
|
|
116
|
-
expect(result.pass).toBe(true);
|
|
117
|
-
expect(el._attempts).toBe(1);
|
|
118
|
-
});
|
|
119
|
-
test('not - failure', async () => {
|
|
120
|
-
const el = await $('sel');
|
|
121
|
-
el._size = function (property) {
|
|
122
|
-
if (property === 'width') {
|
|
123
|
-
return 50;
|
|
124
|
-
}
|
|
125
|
-
if (property === 'height') {
|
|
126
|
-
return 32;
|
|
127
|
-
}
|
|
128
|
-
return { width: 50, height: 32 };
|
|
129
|
-
};
|
|
130
|
-
const result = await toHaveWidth.call({}, el, 50, { wait: 0 });
|
|
131
|
-
const received = getReceived(result.message());
|
|
132
|
-
expect(received).not.toContain('not');
|
|
133
|
-
expect(result.pass).toBe(true);
|
|
134
|
-
});
|
|
135
|
-
test("should return false if sizes don't match", async () => {
|
|
136
|
-
const el = await $('sel');
|
|
137
|
-
el._size = function (property) {
|
|
138
|
-
if (property === 'width') {
|
|
139
|
-
return 50;
|
|
140
|
-
}
|
|
141
|
-
if (property === 'height') {
|
|
142
|
-
return 32;
|
|
143
|
-
}
|
|
144
|
-
return { width: 50, height: 32 };
|
|
145
|
-
};
|
|
146
|
-
const result = await toHaveWidth.bind({})(el, 10, { wait: 1 });
|
|
147
|
-
expect(result.pass).toBe(false);
|
|
148
|
-
});
|
|
149
|
-
test('should return true if sizes match', async () => {
|
|
150
|
-
const el = await $('sel');
|
|
151
|
-
el._size = function (property) {
|
|
152
|
-
if (property === 'width') {
|
|
153
|
-
return 50;
|
|
154
|
-
}
|
|
155
|
-
if (property === 'height') {
|
|
156
|
-
return 32;
|
|
157
|
-
}
|
|
158
|
-
return { width: 50, height: 32 };
|
|
159
|
-
};
|
|
160
|
-
const result = await toHaveWidth.bind({})(el, 50, { wait: 1 });
|
|
161
|
-
expect(result.pass).toBe(true);
|
|
162
|
-
});
|
|
163
|
-
test('message', async () => {
|
|
164
|
-
const el = await $('sel');
|
|
165
|
-
el._size = function () {
|
|
166
|
-
return null;
|
|
167
|
-
};
|
|
168
|
-
const result = await toHaveWidth.call({}, el, 50);
|
|
169
|
-
expect(getExpectMessage(result.message())).toContain('to have width');
|
|
170
|
-
});
|
|
171
|
-
});
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { vi, test, describe, expect, beforeEach } from 'vitest';
|
|
2
|
-
import { $$ } from '@wdio/globals';
|
|
3
|
-
import { getExpectMessage, getReceived, getExpected } from '../../__fixtures__/utils.js';
|
|
4
|
-
import { toBeElementsArrayOfSize } from '../../../src/matchers/elements/toBeElementsArrayOfSize.js';
|
|
5
|
-
const createMockElementArray = (length) => {
|
|
6
|
-
const array = Array.from({ length }, () => ({}));
|
|
7
|
-
const mockArray = {
|
|
8
|
-
selector: 'parent',
|
|
9
|
-
get length() { return array.length; },
|
|
10
|
-
set length(newLength) { array.length = newLength; },
|
|
11
|
-
parent: {
|
|
12
|
-
$: vi.fn(),
|
|
13
|
-
$$: vi.fn().mockReturnValue(array),
|
|
14
|
-
},
|
|
15
|
-
foundWith: '$$',
|
|
16
|
-
props: [],
|
|
17
|
-
[Symbol.iterator]: array[Symbol.iterator].bind(array),
|
|
18
|
-
filter: vi.fn().mockReturnThis(),
|
|
19
|
-
map: vi.fn().mockReturnThis(),
|
|
20
|
-
find: vi.fn().mockReturnThis(),
|
|
21
|
-
forEach: vi.fn(),
|
|
22
|
-
some: vi.fn(),
|
|
23
|
-
every: vi.fn(),
|
|
24
|
-
slice: vi.fn().mockReturnThis(),
|
|
25
|
-
toArray: vi.fn().mockReturnThis(),
|
|
26
|
-
};
|
|
27
|
-
return Object.assign(array, mockArray);
|
|
28
|
-
};
|
|
29
|
-
vi.mock('@wdio/globals', () => ({
|
|
30
|
-
$$: vi.fn().mockImplementation(() => createMockElementArray(2))
|
|
31
|
-
}));
|
|
32
|
-
describe('toBeElementsArrayOfSize', () => {
|
|
33
|
-
let els;
|
|
34
|
-
beforeEach(() => {
|
|
35
|
-
els = $$('parent');
|
|
36
|
-
});
|
|
37
|
-
describe('success', () => {
|
|
38
|
-
test('array of size 2', async () => {
|
|
39
|
-
const beforeAssertion = vi.fn();
|
|
40
|
-
const afterAssertion = vi.fn();
|
|
41
|
-
const result = await toBeElementsArrayOfSize.call({}, els, 2, { beforeAssertion, afterAssertion });
|
|
42
|
-
expect(result.pass).toBe(true);
|
|
43
|
-
expect(beforeAssertion).toBeCalledWith({
|
|
44
|
-
matcherName: 'toBeElementsArrayOfSize',
|
|
45
|
-
expectedValue: 2,
|
|
46
|
-
options: { beforeAssertion, afterAssertion }
|
|
47
|
-
});
|
|
48
|
-
expect(afterAssertion).toBeCalledWith({
|
|
49
|
-
matcherName: 'toBeElementsArrayOfSize',
|
|
50
|
-
expectedValue: 2,
|
|
51
|
-
options: { beforeAssertion, afterAssertion },
|
|
52
|
-
result
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
test('array of size 5', async () => {
|
|
56
|
-
els = createMockElementArray(5);
|
|
57
|
-
const result = await toBeElementsArrayOfSize.call({}, els, 5, {});
|
|
58
|
-
expect(result.pass).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
describe('failure', () => {
|
|
62
|
-
let result;
|
|
63
|
-
beforeEach(async () => {
|
|
64
|
-
result = await toBeElementsArrayOfSize.call({}, els, 5, {});
|
|
65
|
-
});
|
|
66
|
-
test('fails', () => {
|
|
67
|
-
expect(result.pass).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
describe('message shows correctly', () => {
|
|
70
|
-
test('expect message', () => {
|
|
71
|
-
expect(getExpectMessage(result.message())).toContain('to be elements array of size');
|
|
72
|
-
});
|
|
73
|
-
test('expected message', () => {
|
|
74
|
-
expect(getExpected(result.message())).toContain('5');
|
|
75
|
-
});
|
|
76
|
-
test('received message', () => {
|
|
77
|
-
expect(getReceived(result.message())).toContain('2');
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
describe('error catching', () => {
|
|
82
|
-
test('throws error with incorrect size param', async () => {
|
|
83
|
-
await expect(toBeElementsArrayOfSize.call({}, els, '5')).rejects.toThrow('Invalid params passed to toBeElementsArrayOfSize.');
|
|
84
|
-
});
|
|
85
|
-
test('works if size contains options', async () => {
|
|
86
|
-
const result = await toBeElementsArrayOfSize.call({}, els, { lte: 5 });
|
|
87
|
-
expect(result.pass).toBe(true);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
describe('number options', () => {
|
|
91
|
-
test.each([
|
|
92
|
-
['lte', 10, true],
|
|
93
|
-
['lte', 1, false],
|
|
94
|
-
['gte', 1, true],
|
|
95
|
-
['gte', 10, false],
|
|
96
|
-
['gte and lte', { gte: 1, lte: 10 }, true],
|
|
97
|
-
['not gte but is lte', { gte: 10, lte: 10 }, false],
|
|
98
|
-
['not lte but is gte', { gte: 1, lte: 1 }, false],
|
|
99
|
-
])('should handle %s correctly', async (_, option, expected) => {
|
|
100
|
-
const result = await toBeElementsArrayOfSize.call({}, els, typeof option === 'object' ? option : { [_]: option });
|
|
101
|
-
expect(result.pass).toBe(expected);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
describe('array update', () => {
|
|
105
|
-
test('updates the received array when assertion passes', async () => {
|
|
106
|
-
const receivedArray = createMockElementArray(2);
|
|
107
|
-
receivedArray.parent._length = 5;
|
|
108
|
-
receivedArray.parent.$$ = vi.fn().mockReturnValue(createMockElementArray(5));
|
|
109
|
-
const result = await toBeElementsArrayOfSize.call({}, receivedArray, 5);
|
|
110
|
-
expect(result.pass).toBe(true);
|
|
111
|
-
expect(receivedArray.length).toBe(5);
|
|
112
|
-
});
|
|
113
|
-
test('does not update the received array when assertion fails', async () => {
|
|
114
|
-
const receivedArray = createMockElementArray(2);
|
|
115
|
-
const result = await toBeElementsArrayOfSize.call({}, receivedArray, 10);
|
|
116
|
-
expect(result.pass).toBe(false);
|
|
117
|
-
expect(receivedArray.length).toBe(2);
|
|
118
|
-
});
|
|
119
|
-
test('does not modify non-array received values', async () => {
|
|
120
|
-
const nonArrayEls = {
|
|
121
|
-
selector: 'parent',
|
|
122
|
-
length: 2,
|
|
123
|
-
parent: {
|
|
124
|
-
$: vi.fn(),
|
|
125
|
-
$$: vi.fn().mockReturnValue(createMockElementArray(5)),
|
|
126
|
-
},
|
|
127
|
-
foundWith: '$$',
|
|
128
|
-
props: [],
|
|
129
|
-
};
|
|
130
|
-
const result = await toBeElementsArrayOfSize.call({}, nonArrayEls, 5);
|
|
131
|
-
expect(result.pass).toBe(true);
|
|
132
|
-
expect(nonArrayEls.length).toBe(2);
|
|
133
|
-
});
|
|
134
|
-
test('does not alter the array when checking', async () => {
|
|
135
|
-
const receivedArray = createMockElementArray(2);
|
|
136
|
-
const result = await toBeElementsArrayOfSize.call({}, receivedArray, 2);
|
|
137
|
-
expect(result.pass).toBe(true);
|
|
138
|
-
expect(receivedArray.length).toBe(2);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { vi, test, describe, expect } from 'vitest';
|
|
2
|
-
import { toBeRequested } from '../../../src/matchers/mock/toBeRequested.js';
|
|
3
|
-
import { getExpected, getExpectMessage, getReceived, removeColors } from '../../__fixtures__/utils.js';
|
|
4
|
-
vi.mock('@wdio/globals');
|
|
5
|
-
class TestMock {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.on = vi.fn();
|
|
8
|
-
this._calls = [];
|
|
9
|
-
}
|
|
10
|
-
get calls() {
|
|
11
|
-
return this._calls;
|
|
12
|
-
}
|
|
13
|
-
abort() { return Promise.resolve(); }
|
|
14
|
-
abortOnce() { return Promise.resolve(); }
|
|
15
|
-
respond() { return Promise.resolve(); }
|
|
16
|
-
respondOnce() { return Promise.resolve(); }
|
|
17
|
-
clear() { return Promise.resolve(); }
|
|
18
|
-
restore() { return Promise.resolve(); }
|
|
19
|
-
waitForResponse() { return Promise.resolve(true); }
|
|
20
|
-
}
|
|
21
|
-
const mockMatch = {
|
|
22
|
-
body: 'foo',
|
|
23
|
-
url: '/foo/bar',
|
|
24
|
-
method: 'POST',
|
|
25
|
-
headers: {},
|
|
26
|
-
responseHeaders: {},
|
|
27
|
-
statusCode: 200,
|
|
28
|
-
initialPriority: 'Low',
|
|
29
|
-
referrerPolicy: 'origin'
|
|
30
|
-
};
|
|
31
|
-
describe('toBeRequested', () => {
|
|
32
|
-
test('wait for success', async () => {
|
|
33
|
-
const mock = new TestMock();
|
|
34
|
-
const result = await toBeRequested(mock);
|
|
35
|
-
expect(result.pass).toBe(false);
|
|
36
|
-
setTimeout(() => {
|
|
37
|
-
mock.calls.push(mockMatch);
|
|
38
|
-
mock.calls.push(mockMatch);
|
|
39
|
-
}, 10);
|
|
40
|
-
const beforeAssertion = vi.fn();
|
|
41
|
-
const afterAssertion = vi.fn();
|
|
42
|
-
const result2 = await toBeRequested(mock, { beforeAssertion, afterAssertion });
|
|
43
|
-
expect(result2.pass).toBe(true);
|
|
44
|
-
expect(beforeAssertion).toBeCalledWith({
|
|
45
|
-
matcherName: 'toBeRequestedTimes',
|
|
46
|
-
expectedValue: { gte: 1 },
|
|
47
|
-
options: { beforeAssertion, afterAssertion }
|
|
48
|
-
});
|
|
49
|
-
expect(afterAssertion).toBeCalledWith({
|
|
50
|
-
matcherName: 'toBeRequestedTimes',
|
|
51
|
-
expectedValue: { gte: 1 },
|
|
52
|
-
options: { beforeAssertion, afterAssertion },
|
|
53
|
-
result: result2
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
test('not to be called', async () => {
|
|
57
|
-
const mock = new TestMock();
|
|
58
|
-
const result = await toBeRequested.call({ isNot: true }, mock);
|
|
59
|
-
expect(result.pass).toBe(false);
|
|
60
|
-
mock.calls.push(mockMatch);
|
|
61
|
-
const result4 = await toBeRequested.call({ isNot: true }, mock);
|
|
62
|
-
expect(result4.pass).toBe(true);
|
|
63
|
-
});
|
|
64
|
-
test('message', async () => {
|
|
65
|
-
const mock = new TestMock();
|
|
66
|
-
const message = removeColors((await toBeRequested(mock)).message());
|
|
67
|
-
expect(getExpectMessage(message)).toBe('Expect mock to be called');
|
|
68
|
-
expect(getReceived(message)).toBe('Received: 0');
|
|
69
|
-
expect(getExpected(message)).toBe('Expected: ">= 1"');
|
|
70
|
-
const result2 = await toBeRequested.call({ isNot: true }, mock);
|
|
71
|
-
expect(result2.message()).toContain('Expect mock not to be called');
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { vi, test, describe, expect } from 'vitest';
|
|
2
|
-
import { toBeRequestedTimes } from '../../../src/matchers/mock/toBeRequestedTimes.js';
|
|
3
|
-
import { removeColors, getReceived, getExpected, getExpectMessage } from '../../__fixtures__/utils.js';
|
|
4
|
-
vi.mock('@wdio/globals');
|
|
5
|
-
class TestMock {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.on = vi.fn();
|
|
8
|
-
this._calls = [];
|
|
9
|
-
}
|
|
10
|
-
get calls() {
|
|
11
|
-
return this._calls;
|
|
12
|
-
}
|
|
13
|
-
abort() { return Promise.resolve(); }
|
|
14
|
-
abortOnce() { return Promise.resolve(); }
|
|
15
|
-
respond() { return Promise.resolve(); }
|
|
16
|
-
respondOnce() { return Promise.resolve(); }
|
|
17
|
-
clear() { return Promise.resolve(); }
|
|
18
|
-
restore() { return Promise.resolve(); }
|
|
19
|
-
waitForResponse() { return Promise.resolve(true); }
|
|
20
|
-
}
|
|
21
|
-
const mockMatch = {
|
|
22
|
-
body: 'foo',
|
|
23
|
-
url: '/foo/bar',
|
|
24
|
-
method: 'POST',
|
|
25
|
-
headers: {},
|
|
26
|
-
responseHeaders: {},
|
|
27
|
-
statusCode: 200,
|
|
28
|
-
initialPriority: 'Low',
|
|
29
|
-
referrerPolicy: 'origin'
|
|
30
|
-
};
|
|
31
|
-
describe('toBeRequestedTimes', () => {
|
|
32
|
-
test('wait for success', async () => {
|
|
33
|
-
const mock = new TestMock();
|
|
34
|
-
setTimeout(() => {
|
|
35
|
-
mock.calls.push(mockMatch);
|
|
36
|
-
}, 10);
|
|
37
|
-
const beforeAssertion = vi.fn();
|
|
38
|
-
const afterAssertion = vi.fn();
|
|
39
|
-
const result = await toBeRequestedTimes.call({}, mock, 1, { beforeAssertion, afterAssertion });
|
|
40
|
-
expect(result.pass).toBe(true);
|
|
41
|
-
expect(beforeAssertion).toBeCalledWith({
|
|
42
|
-
matcherName: 'toBeRequestedTimes',
|
|
43
|
-
expectedValue: 1,
|
|
44
|
-
options: { beforeAssertion, afterAssertion }
|
|
45
|
-
});
|
|
46
|
-
expect(afterAssertion).toBeCalledWith({
|
|
47
|
-
matcherName: 'toBeRequestedTimes',
|
|
48
|
-
expectedValue: 1,
|
|
49
|
-
options: { beforeAssertion, afterAssertion },
|
|
50
|
-
result
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
test('wait for success using number options', async () => {
|
|
54
|
-
const mock = new TestMock();
|
|
55
|
-
setTimeout(() => {
|
|
56
|
-
mock.calls.push(mockMatch);
|
|
57
|
-
}, 10);
|
|
58
|
-
const result = await toBeRequestedTimes.call({}, mock, { gte: 1 });
|
|
59
|
-
expect(result.pass).toBe(true);
|
|
60
|
-
const result2 = await toBeRequestedTimes.call({}, mock, { eq: 1 });
|
|
61
|
-
expect(result2.pass).toBe(true);
|
|
62
|
-
});
|
|
63
|
-
test('wait but failure', async () => {
|
|
64
|
-
const mock = new TestMock();
|
|
65
|
-
const result = await toBeRequestedTimes.call({}, mock, 1);
|
|
66
|
-
expect(result.pass).toBe(false);
|
|
67
|
-
setTimeout(() => {
|
|
68
|
-
mock.calls.push(mockMatch);
|
|
69
|
-
mock.calls.push(mockMatch);
|
|
70
|
-
}, 10);
|
|
71
|
-
const result2 = await toBeRequestedTimes.call({}, mock, 1);
|
|
72
|
-
expect(result2.pass).toBe(false);
|
|
73
|
-
const result3 = await toBeRequestedTimes.call({}, mock, 2);
|
|
74
|
-
expect(result3.pass).toBe(true);
|
|
75
|
-
const result4 = await toBeRequestedTimes.call({}, mock, { gte: 2 });
|
|
76
|
-
expect(result4.pass).toBe(true);
|
|
77
|
-
const result5 = await toBeRequestedTimes.call({}, mock, { lte: 2 });
|
|
78
|
-
expect(result5.pass).toBe(true);
|
|
79
|
-
const result6 = await toBeRequestedTimes.call({}, mock, { lte: 3 });
|
|
80
|
-
expect(result6.pass).toBe(true);
|
|
81
|
-
});
|
|
82
|
-
test('not to be called', async () => {
|
|
83
|
-
const mock = new TestMock();
|
|
84
|
-
const result = await toBeRequestedTimes.call({ isNot: true }, mock, 0);
|
|
85
|
-
expect(result.pass).toBe(true);
|
|
86
|
-
const result2 = await toBeRequestedTimes.call({ isNot: true }, mock, 1);
|
|
87
|
-
expect(result2.pass).toBe(false);
|
|
88
|
-
mock.calls.push(mockMatch);
|
|
89
|
-
const result3 = await toBeRequestedTimes.call({ isNot: true }, mock, 0);
|
|
90
|
-
expect(result3.pass).toBe(false);
|
|
91
|
-
const result4 = await toBeRequestedTimes.call({ isNot: true }, mock, 1);
|
|
92
|
-
expect(result4.pass).toBe(true);
|
|
93
|
-
});
|
|
94
|
-
test('message', async () => {
|
|
95
|
-
const mock = new TestMock();
|
|
96
|
-
const result = await toBeRequestedTimes.call({}, mock, 0);
|
|
97
|
-
expect(result.message()).toContain('Expect mock to be called 0 times');
|
|
98
|
-
const result2 = await toBeRequestedTimes.call({}, mock, 1);
|
|
99
|
-
expect(result2.message()).toContain('Expect mock to be called 1 time');
|
|
100
|
-
const result3 = await toBeRequestedTimes.call({}, mock, 2);
|
|
101
|
-
expect(result3.message()).toContain('Expect mock to be called 2 times');
|
|
102
|
-
const result4 = await toBeRequestedTimes.call({}, mock, { gte: 3 });
|
|
103
|
-
const message4 = removeColors(result4.message());
|
|
104
|
-
expect(getExpectMessage(message4)).toBe('Expect mock to be called times');
|
|
105
|
-
expect(getExpected(message4)).toBe('Expected: ">= 3"');
|
|
106
|
-
expect(getReceived(message4)).toBe('Received: 0');
|
|
107
|
-
});
|
|
108
|
-
});
|