expect-webdriverio 5.3.2 → 5.3.3
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/test/__fixtures__/utils.js +19 -0
- package/lib/test/index.test.js +8 -0
- package/lib/test/matchers/beMatchers.test.js +109 -0
- package/lib/test/matchers/browser/toHaveClipboardText.test.js +21 -0
- package/lib/test/matchers/browserMatchers.test.js +102 -0
- package/lib/test/matchers/element/toBeDisabled.test.js +121 -0
- package/lib/test/matchers/element/toHaveAttribute.test.js +131 -0
- package/lib/test/matchers/element/toHaveChildren.test.js +62 -0
- package/lib/test/matchers/element/toHaveComputedLabel.test.js +284 -0
- package/lib/test/matchers/element/toHaveComputedRole.test.js +284 -0
- package/lib/test/matchers/element/toHaveElementClass.test.js +125 -0
- package/lib/test/matchers/element/toHaveElementProperty.test.js +111 -0
- package/lib/test/matchers/element/toHaveHTML.test.js +291 -0
- package/lib/test/matchers/element/toHaveHeight.test.js +171 -0
- package/lib/test/matchers/element/toHaveHref.test.js +54 -0
- package/lib/test/matchers/element/toHaveId.test.js +54 -0
- package/lib/test/matchers/element/toHaveSize.test.js +109 -0
- package/lib/test/matchers/element/toHaveStyle.test.js +199 -0
- package/lib/test/matchers/element/toHaveText.test.js +333 -0
- package/lib/test/matchers/element/toHaveValue.test.js +81 -0
- package/lib/test/matchers/element/toHaveWidth.test.js +171 -0
- package/lib/test/matchers/elements/toBeElementsArrayOfSize.test.js +141 -0
- package/lib/test/matchers/mock/toBeRequested.test.js +73 -0
- package/lib/test/matchers/mock/toBeRequestedTimes.test.js +108 -0
- package/lib/test/matchers/mock/toBeRequestedWith.test.js +343 -0
- package/lib/test/matchers.test.js +54 -0
- package/lib/test/snapshot.test.js +53 -0
- package/lib/test/softAssertions.test.js +332 -0
- package/lib/test/util/elementsUtil.test.js +18 -0
- package/lib/test/util/formatMessage.test.js +96 -0
- package/lib/test/util/refetchElements.test.js +19 -0
- package/lib/test/utils.test.js +117 -0
- package/lib/{tsconfig.build.tsbuildinfo → tsconfig.tsbuildinfo} +1 -1
- package/package.json +2 -2
- package/types/expect-webdriverio.d.ts +39 -28
- package/types/standalone.d.ts +2 -0
- /package/lib/{constants.js → src/constants.js} +0 -0
- /package/lib/{index.js → src/index.js} +0 -0
- /package/lib/{jasmineUtils.js → src/jasmineUtils.js} +0 -0
- /package/lib/{matchers → src/matchers}/browser/toHaveClipboardText.js +0 -0
- /package/lib/{matchers → src/matchers}/browser/toHaveTitle.js +0 -0
- /package/lib/{matchers → src/matchers}/browser/toHaveUrl.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeClickable.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeDisabled.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeDisplayed.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeDisplayedInViewport.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeEnabled.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeExisting.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeFocused.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeSelected.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveAttribute.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveChildren.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveClass.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveComputedLabel.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveComputedRole.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveElementProperty.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveHTML.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveHeight.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveHref.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveId.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveSize.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveStyle.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveText.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveValue.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveWidth.js +0 -0
- /package/lib/{matchers → src/matchers}/elements/toBeElementsArrayOfSize.js +0 -0
- /package/lib/{matchers → src/matchers}/mock/toBeRequested.js +0 -0
- /package/lib/{matchers → src/matchers}/mock/toBeRequestedTimes.js +0 -0
- /package/lib/{matchers → src/matchers}/mock/toBeRequestedWith.js +0 -0
- /package/lib/{matchers → src/matchers}/snapshot.js +0 -0
- /package/lib/{matchers.js → src/matchers.js} +0 -0
- /package/lib/{snapshot.js → src/snapshot.js} +0 -0
- /package/lib/{softAssert.js → src/softAssert.js} +0 -0
- /package/lib/{softAssertService.js → src/softAssertService.js} +0 -0
- /package/lib/{softExpect.js → src/softExpect.js} +0 -0
- /package/lib/{types.js → src/types.js} +0 -0
- /package/lib/{util → src/util}/elementsUtil.js +0 -0
- /package/lib/{util → src/util}/executeCommand.js +0 -0
- /package/lib/{util → src/util}/formatMessage.js +0 -0
- /package/lib/{util → src/util}/refetchElements.js +0 -0
- /package/lib/{utils.js → src/utils.js} +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { $ } from '@wdio/globals';
|
|
2
|
+
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
3
|
+
import { getExpectMessage, getExpected, getReceived } from '../../__fixtures__/utils.js';
|
|
4
|
+
import { toHaveElementClass } from '../../../src/matchers/element/toHaveClass.js';
|
|
5
|
+
vi.mock('@wdio/globals');
|
|
6
|
+
describe('toHaveElementClass', () => {
|
|
7
|
+
let el;
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
el = await $('sel');
|
|
10
|
+
el.getAttribute = vi.fn().mockImplementation((attribute) => {
|
|
11
|
+
if (attribute === 'class') {
|
|
12
|
+
return 'some-class another-class yet-another-class';
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
test('success when class name is present', async () => {
|
|
18
|
+
const beforeAssertion = vi.fn();
|
|
19
|
+
const afterAssertion = vi.fn();
|
|
20
|
+
const result = await toHaveElementClass.call({}, el, 'some-class', { beforeAssertion, afterAssertion });
|
|
21
|
+
expect(result.pass).toBe(true);
|
|
22
|
+
expect(beforeAssertion).toBeCalledWith({
|
|
23
|
+
matcherName: 'toHaveElementClass',
|
|
24
|
+
expectedValue: 'some-class',
|
|
25
|
+
options: { beforeAssertion, afterAssertion }
|
|
26
|
+
});
|
|
27
|
+
expect(afterAssertion).toBeCalledWith({
|
|
28
|
+
matcherName: 'toHaveElementClass',
|
|
29
|
+
expectedValue: 'some-class',
|
|
30
|
+
options: { beforeAssertion, afterAssertion },
|
|
31
|
+
result
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
test('success when including surrounding spaces and asymmetric matcher', async () => {
|
|
35
|
+
const result = await toHaveElementClass.call({}, el, expect.stringContaining('some-class '));
|
|
36
|
+
expect(result.pass).toBe(true);
|
|
37
|
+
const result2 = await toHaveElementClass.call({}, el, expect.stringContaining(' another-class '));
|
|
38
|
+
expect(result2.pass).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
test('success with RegExp when class name is present', async () => {
|
|
41
|
+
const result = await toHaveElementClass.call({}, el, /sOmE-cLaSs/i);
|
|
42
|
+
expect(result.pass).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
test('success if array matches with class', async () => {
|
|
45
|
+
const result = await toHaveElementClass.call({}, el, ['some-class', 'yet-another-class']);
|
|
46
|
+
expect(result.pass).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
test('failure if the classes do not match', async () => {
|
|
49
|
+
const result = await toHaveElementClass.call({}, el, 'someclass', { message: 'Not found!' });
|
|
50
|
+
expect(result.pass).toBe(false);
|
|
51
|
+
expect(getExpectMessage(result.message())).toContain('Not found!');
|
|
52
|
+
});
|
|
53
|
+
test('failure if array does not match with class', async () => {
|
|
54
|
+
const result = await toHaveElementClass.call({}, el, ['someclass', 'anotherclass']);
|
|
55
|
+
expect(result.pass).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
describe('options', () => {
|
|
58
|
+
test('should fail when class is not a string', async () => {
|
|
59
|
+
el.getAttribute = vi.fn().mockImplementation(() => {
|
|
60
|
+
return null;
|
|
61
|
+
});
|
|
62
|
+
const result = await toHaveElementClass.call({}, el, 'some-class');
|
|
63
|
+
expect(result.pass).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
test('should pass when trimming the attribute', async () => {
|
|
66
|
+
el.getAttribute = vi.fn().mockImplementation(() => {
|
|
67
|
+
return ' some-class ';
|
|
68
|
+
});
|
|
69
|
+
const result = await toHaveElementClass.call({}, el, 'some-class', { trim: true });
|
|
70
|
+
expect(result.pass).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
test('should pass when ignore the case', async () => {
|
|
73
|
+
const result = await toHaveElementClass.call({}, el, 'sOme-ClAsS', { ignoreCase: true });
|
|
74
|
+
expect(result.pass).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
test('should pass if containing', async () => {
|
|
77
|
+
const result = await toHaveElementClass.call({}, el, 'some', { containing: true });
|
|
78
|
+
expect(result.pass).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
test('should pass if array ignores the case', async () => {
|
|
81
|
+
const result = await toHaveElementClass.call({}, el, ['sOme-ClAsS', 'anOther-ClAsS'], { ignoreCase: true });
|
|
82
|
+
expect(result.pass).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('failure when class name is not present', () => {
|
|
86
|
+
let result;
|
|
87
|
+
beforeEach(async () => {
|
|
88
|
+
result = await toHaveElementClass.call({}, el, 'test');
|
|
89
|
+
});
|
|
90
|
+
test('failure', () => {
|
|
91
|
+
expect(result.pass).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
describe('message shows correctly', () => {
|
|
94
|
+
test('expect message', () => {
|
|
95
|
+
expect(getExpectMessage(result.message())).toContain('to have class');
|
|
96
|
+
});
|
|
97
|
+
test('expected message', () => {
|
|
98
|
+
expect(getExpected(result.message())).toContain('test');
|
|
99
|
+
});
|
|
100
|
+
test('received message', () => {
|
|
101
|
+
expect(getReceived(result.message())).toContain('some-class another-class');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe('failure with RegExp when class name is not present', () => {
|
|
106
|
+
let result;
|
|
107
|
+
beforeEach(async () => {
|
|
108
|
+
result = await toHaveElementClass.call({}, el, /WDIO/);
|
|
109
|
+
});
|
|
110
|
+
test('failure', () => {
|
|
111
|
+
expect(result.pass).toBe(false);
|
|
112
|
+
});
|
|
113
|
+
describe('message shows correctly', () => {
|
|
114
|
+
test('expect message', () => {
|
|
115
|
+
expect(getExpectMessage(result.message())).toContain('to have class');
|
|
116
|
+
});
|
|
117
|
+
test('expected message', () => {
|
|
118
|
+
expect(getExpected(result.message())).toContain('/WDIO/');
|
|
119
|
+
});
|
|
120
|
+
test('received message', () => {
|
|
121
|
+
expect(getReceived(result.message())).toContain('some-class another-class');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { vi, test, describe, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { $ } from '@wdio/globals';
|
|
3
|
+
import { getExpectMessage, getExpected, getReceived } from '../../__fixtures__/utils.js';
|
|
4
|
+
import { toHaveElementProperty } from '../../../src/matchers/element/toHaveElementProperty.js';
|
|
5
|
+
vi.mock('@wdio/globals');
|
|
6
|
+
describe('toHaveElementProperty', () => {
|
|
7
|
+
test('ignore case of stringified value', async () => {
|
|
8
|
+
const el = await $('sel');
|
|
9
|
+
el._attempts = 0;
|
|
10
|
+
el._value = function () {
|
|
11
|
+
this._attempts++;
|
|
12
|
+
return 'iphone';
|
|
13
|
+
};
|
|
14
|
+
const beforeAssertion = vi.fn();
|
|
15
|
+
const afterAssertion = vi.fn();
|
|
16
|
+
const result = await toHaveElementProperty.call({}, el, 'property', 'iPhone', { wait: 0, ignoreCase: true, beforeAssertion, afterAssertion });
|
|
17
|
+
expect(result.pass).toBe(true);
|
|
18
|
+
expect(el._attempts).toBe(1);
|
|
19
|
+
expect(beforeAssertion).toBeCalledWith({
|
|
20
|
+
matcherName: 'toHaveElementProperty',
|
|
21
|
+
expectedValue: ['property', 'iPhone'],
|
|
22
|
+
options: { wait: 0, ignoreCase: true, beforeAssertion, afterAssertion }
|
|
23
|
+
});
|
|
24
|
+
expect(afterAssertion).toBeCalledWith({
|
|
25
|
+
matcherName: 'toHaveElementProperty',
|
|
26
|
+
expectedValue: ['property', 'iPhone'],
|
|
27
|
+
options: { wait: 0, ignoreCase: true, beforeAssertion, afterAssertion },
|
|
28
|
+
result
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
test('assymeric match', async () => {
|
|
32
|
+
const el = await $('sel');
|
|
33
|
+
el._value = function () {
|
|
34
|
+
return 'iphone';
|
|
35
|
+
};
|
|
36
|
+
const result = await toHaveElementProperty.call({}, el, 'property', expect.stringContaining('phone'));
|
|
37
|
+
expect(result.pass).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
test('should return false if values dont match', async () => {
|
|
40
|
+
const el = await $('sel');
|
|
41
|
+
el._value = function () {
|
|
42
|
+
return 'iphone';
|
|
43
|
+
};
|
|
44
|
+
const result = await toHaveElementProperty.bind({ isNot: true })(el, 'property', 'foobar', { wait: 1 });
|
|
45
|
+
expect(result.pass).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
test('should return true if values match', async () => {
|
|
48
|
+
const el = await $('sel');
|
|
49
|
+
el._value = function () {
|
|
50
|
+
return 'iphone';
|
|
51
|
+
};
|
|
52
|
+
const result = await toHaveElementProperty.bind({ isNot: true })(el, 'property', 'iphone', { wait: 1 });
|
|
53
|
+
expect(result.pass).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
test('with RegExp should return true if values match', async () => {
|
|
56
|
+
const el = await $('sel');
|
|
57
|
+
el._value = function () {
|
|
58
|
+
return 'iphone';
|
|
59
|
+
};
|
|
60
|
+
const result = await toHaveElementProperty.call({}, el, 'property', /iPhOnE/i);
|
|
61
|
+
expect(result.pass).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
test('should return false for null input', async () => {
|
|
64
|
+
const el = await $('sel');
|
|
65
|
+
el._value = function () {
|
|
66
|
+
return undefined;
|
|
67
|
+
};
|
|
68
|
+
const result = await toHaveElementProperty.bind({ isNot: true })(el, 'property', 'iphone', { wait: 1 });
|
|
69
|
+
expect(result.pass).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
test('should return true if value is null', async () => {
|
|
72
|
+
const el = await $('sel');
|
|
73
|
+
el._value = function () {
|
|
74
|
+
return 'Test Value';
|
|
75
|
+
};
|
|
76
|
+
const result = await toHaveElementProperty.bind({ isNot: true })(el, 'property', null);
|
|
77
|
+
expect(result.pass).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
test('should return false if value is non-string', async () => {
|
|
80
|
+
const el = await $('sel');
|
|
81
|
+
el._value = function () {
|
|
82
|
+
return 5;
|
|
83
|
+
};
|
|
84
|
+
const result = await toHaveElementProperty.bind({ isNot: true })(el, 'property', 'Test Value');
|
|
85
|
+
expect(result.pass).toBe(false);
|
|
86
|
+
});
|
|
87
|
+
describe('failure with RegExp when value does not match', () => {
|
|
88
|
+
let result;
|
|
89
|
+
beforeEach(async () => {
|
|
90
|
+
const el = await $('sel');
|
|
91
|
+
el._value = function () {
|
|
92
|
+
return 'iphone';
|
|
93
|
+
};
|
|
94
|
+
result = await toHaveElementProperty.call({}, el, 'property', /WDIO/);
|
|
95
|
+
});
|
|
96
|
+
test('failure', () => {
|
|
97
|
+
expect(result.pass).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
describe('message shows correctly', () => {
|
|
100
|
+
test('expect message', () => {
|
|
101
|
+
expect(getExpectMessage(result.message())).toContain('to have property');
|
|
102
|
+
});
|
|
103
|
+
test('expected message', () => {
|
|
104
|
+
expect(getExpected(result.message())).toContain('/WDIO/');
|
|
105
|
+
});
|
|
106
|
+
test('received message', () => {
|
|
107
|
+
expect(getReceived(result.message())).toContain('iphone');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,291 @@
|
|
|
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 { toHaveHTML } from '../../../src/matchers/element/toHaveHTML.js';
|
|
5
|
+
vi.mock('@wdio/globals');
|
|
6
|
+
describe('toHaveHTML', () => {
|
|
7
|
+
test('wait for success', async () => {
|
|
8
|
+
const el = await $('sel');
|
|
9
|
+
el._attempts = 2;
|
|
10
|
+
el._html = function () {
|
|
11
|
+
if (this._attempts > 0) {
|
|
12
|
+
this._attempts--;
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
return '<div>foo</div>';
|
|
16
|
+
};
|
|
17
|
+
const beforeAssertion = vi.fn();
|
|
18
|
+
const afterAssertion = vi.fn();
|
|
19
|
+
const result = await toHaveHTML.call({}, el, '<div>foo</div>', { ignoreCase: true, beforeAssertion, afterAssertion });
|
|
20
|
+
expect(result.pass).toBe(true);
|
|
21
|
+
expect(el._attempts).toBe(0);
|
|
22
|
+
expect(beforeAssertion).toBeCalledWith({
|
|
23
|
+
matcherName: 'toHaveHTML',
|
|
24
|
+
expectedValue: '<div>foo</div>',
|
|
25
|
+
options: { ignoreCase: true, beforeAssertion, afterAssertion }
|
|
26
|
+
});
|
|
27
|
+
expect(afterAssertion).toBeCalledWith({
|
|
28
|
+
matcherName: 'toHaveHTML',
|
|
29
|
+
expectedValue: '<div>foo</div>',
|
|
30
|
+
options: { ignoreCase: true, beforeAssertion, afterAssertion },
|
|
31
|
+
result
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
test('wait but failure', async () => {
|
|
35
|
+
const el = await $('sel');
|
|
36
|
+
el._html = function () {
|
|
37
|
+
throw new Error('some error');
|
|
38
|
+
};
|
|
39
|
+
await expect(() => toHaveHTML.call({}, el, '<div>foo</div>', { ignoreCase: true }))
|
|
40
|
+
.rejects.toThrow('some error');
|
|
41
|
+
});
|
|
42
|
+
test('success on the first attempt', async () => {
|
|
43
|
+
const el = await $('sel');
|
|
44
|
+
el._attempts = 0;
|
|
45
|
+
el._html = function () {
|
|
46
|
+
this._attempts++;
|
|
47
|
+
return '<div>foo</div>';
|
|
48
|
+
};
|
|
49
|
+
const result = await toHaveHTML.call({}, el, '<div>foo</div>', { ignoreCase: true });
|
|
50
|
+
expect(result.pass).toBe(true);
|
|
51
|
+
expect(el._attempts).toBe(1);
|
|
52
|
+
});
|
|
53
|
+
test('no wait - failure', async () => {
|
|
54
|
+
const el = await $('sel');
|
|
55
|
+
el._attempts = 0;
|
|
56
|
+
el._html = function () {
|
|
57
|
+
this._attempts++;
|
|
58
|
+
return '<div>foo</div>';
|
|
59
|
+
};
|
|
60
|
+
const result = await toHaveHTML.call({}, el, 'foo', { wait: 0 });
|
|
61
|
+
expect(result.pass).toBe(false);
|
|
62
|
+
expect(el._attempts).toBe(1);
|
|
63
|
+
});
|
|
64
|
+
test('no wait - success', async () => {
|
|
65
|
+
const el = await $('sel');
|
|
66
|
+
el._attempts = 0;
|
|
67
|
+
el._html = function () {
|
|
68
|
+
this._attempts++;
|
|
69
|
+
return '<div>foo</div>';
|
|
70
|
+
};
|
|
71
|
+
const result = await toHaveHTML.call({}, el, '<div>foo</div>', { wait: 0 });
|
|
72
|
+
expect(result.pass).toBe(true);
|
|
73
|
+
expect(el._attempts).toBe(1);
|
|
74
|
+
});
|
|
75
|
+
test('not - failure', async () => {
|
|
76
|
+
const el = await $('sel');
|
|
77
|
+
el._html = function () {
|
|
78
|
+
return '<div>foo</div>';
|
|
79
|
+
};
|
|
80
|
+
const result = await toHaveHTML.call({ isNot: true }, el, '<div>foo</div>', { wait: 0 });
|
|
81
|
+
const received = getReceived(result.message());
|
|
82
|
+
expect(received).not.toContain('not');
|
|
83
|
+
expect(result.pass).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
test("should return false if htmls don't match", async () => {
|
|
86
|
+
const el = await $('sel');
|
|
87
|
+
el._html = function () {
|
|
88
|
+
return '<div>foo</div>';
|
|
89
|
+
};
|
|
90
|
+
const result = await toHaveHTML.bind({ isNot: true })(el, 'foobar', { wait: 1 });
|
|
91
|
+
expect(result.pass).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
test('should return true if htmls match', async () => {
|
|
94
|
+
const el = await $('sel');
|
|
95
|
+
el._html = function () {
|
|
96
|
+
return '<div>foo</div>';
|
|
97
|
+
};
|
|
98
|
+
const result = await toHaveHTML.bind({ isNot: true })(el, '<div>foo</div>', { wait: 1 });
|
|
99
|
+
expect(result.pass).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
test('should return true if actual html + single replacer matches the expected html', async () => {
|
|
102
|
+
const el = await $('sel');
|
|
103
|
+
el._html = function () {
|
|
104
|
+
return '<div>foo</div>';
|
|
105
|
+
};
|
|
106
|
+
const result = await toHaveHTML.bind({})(el, '<div>bar</div>', { replace: ['foo', 'bar'] });
|
|
107
|
+
expect(result.pass).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
test('should return true if actual html + replace (string) matches the expected html', async () => {
|
|
110
|
+
const el = await $('sel');
|
|
111
|
+
el._html = function () {
|
|
112
|
+
return '<div>foo</div>';
|
|
113
|
+
};
|
|
114
|
+
const result = await toHaveHTML.bind({})(el, '<div>bar</div>', { replace: [['foo', 'bar']] });
|
|
115
|
+
expect(result.pass).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
test('should return true if actual html + replace (regex) matches the expected html', async () => {
|
|
118
|
+
const el = await $('sel');
|
|
119
|
+
el._html = function () {
|
|
120
|
+
return '<div>foo</div>';
|
|
121
|
+
};
|
|
122
|
+
const result = await toHaveHTML.bind({})(el, '<div>bar</div>', { replace: [[/foo/, 'bar']] });
|
|
123
|
+
expect(result.pass).toBe(true);
|
|
124
|
+
});
|
|
125
|
+
test('should return true if actual html starts with expected html', async () => {
|
|
126
|
+
const el = await $('sel');
|
|
127
|
+
el._html = function () {
|
|
128
|
+
return '<div>foo</div>';
|
|
129
|
+
};
|
|
130
|
+
const result = await toHaveHTML.bind({})(el, '<div>', { atStart: true });
|
|
131
|
+
expect(result.pass).toBe(true);
|
|
132
|
+
});
|
|
133
|
+
test('should return true if actual html ends with expected html', async () => {
|
|
134
|
+
const el = await $('sel');
|
|
135
|
+
el._html = function () {
|
|
136
|
+
return '<div>foo</div>';
|
|
137
|
+
};
|
|
138
|
+
const result = await toHaveHTML.bind({})(el, '</div>', { atEnd: true });
|
|
139
|
+
expect(result.pass).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
test('should return true if actual html contains the expected html at the given index', async () => {
|
|
142
|
+
const el = await $('sel');
|
|
143
|
+
el._html = function () {
|
|
144
|
+
return '<div>foo</div>';
|
|
145
|
+
};
|
|
146
|
+
const result = await toHaveHTML.bind({})(el, 'iv>foo', { atIndex: 2 });
|
|
147
|
+
expect(result.pass).toBe(true);
|
|
148
|
+
});
|
|
149
|
+
test('should return true if actual html equals the expected html with includeSelectorTag set to false', async () => {
|
|
150
|
+
const el = await $('sel');
|
|
151
|
+
el._html = function (includeSelectorTag) {
|
|
152
|
+
return includeSelectorTag ? '<div><div>foo</div></div>' : '<div>foo</div>';
|
|
153
|
+
};
|
|
154
|
+
const result = await toHaveHTML.bind({})(el, '<div>foo</div>', { includeSelectorTag: false });
|
|
155
|
+
expect(result.pass).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
test('should return true if actual html equals the expected html with includeSelectorTag set to false', async () => {
|
|
158
|
+
const el = await $('sel');
|
|
159
|
+
el._html = function (includeSelectorTag) {
|
|
160
|
+
return includeSelectorTag ? '<div><div>foo</div></div>' : '<div>foo</div>';
|
|
161
|
+
};
|
|
162
|
+
const result = await toHaveHTML.bind({})(el, '<div><div>foo</div></div>', {
|
|
163
|
+
includeSelectorTag: true,
|
|
164
|
+
});
|
|
165
|
+
expect(result.pass).toBe(true);
|
|
166
|
+
});
|
|
167
|
+
test('message', async () => {
|
|
168
|
+
const el = await $('sel');
|
|
169
|
+
el._html = function () {
|
|
170
|
+
return '';
|
|
171
|
+
};
|
|
172
|
+
const result = await toHaveHTML.call({}, el, '<div>foo</div>');
|
|
173
|
+
expect(getExpectMessage(result.message())).toContain('to have HTML');
|
|
174
|
+
});
|
|
175
|
+
test('success if array matches with html and ignoreCase', async () => {
|
|
176
|
+
const el = await $('sel');
|
|
177
|
+
el._attempts = 0;
|
|
178
|
+
el._html = function () {
|
|
179
|
+
this._attempts++;
|
|
180
|
+
return '<div>foo</div>';
|
|
181
|
+
};
|
|
182
|
+
const result = await toHaveHTML.call({}, el, ['div', '<div>foo</div>'], { ignoreCase: true });
|
|
183
|
+
expect(result.pass).toBe(true);
|
|
184
|
+
expect(el._attempts).toBe(1);
|
|
185
|
+
});
|
|
186
|
+
test('success if array matches with html and trim', async () => {
|
|
187
|
+
const el = await $('sel');
|
|
188
|
+
el._attempts = 0;
|
|
189
|
+
el._html = function () {
|
|
190
|
+
this._attempts++;
|
|
191
|
+
return ' <div>foo</div> ';
|
|
192
|
+
};
|
|
193
|
+
const result = await toHaveHTML.call({}, el, ['div', '<div>foo</div>', 'toto'], { trim: true });
|
|
194
|
+
expect(result.pass).toBe(true);
|
|
195
|
+
expect(el._attempts).toBe(1);
|
|
196
|
+
});
|
|
197
|
+
test('success if array matches with html and replace (string)', async () => {
|
|
198
|
+
const el = await $('sel');
|
|
199
|
+
el._attempts = 0;
|
|
200
|
+
el._html = function () {
|
|
201
|
+
this._attempts++;
|
|
202
|
+
return '<div>foo</div>';
|
|
203
|
+
};
|
|
204
|
+
const result = await toHaveHTML.call({}, el, ['div', '<div>foo</div>', 'toto'], {
|
|
205
|
+
replace: [['Web', 'Browser']],
|
|
206
|
+
});
|
|
207
|
+
expect(result.pass).toBe(true);
|
|
208
|
+
expect(el._attempts).toBe(1);
|
|
209
|
+
});
|
|
210
|
+
test('success if array matches with html and replace (regex)', async () => {
|
|
211
|
+
const el = await $('sel');
|
|
212
|
+
el._attempts = 0;
|
|
213
|
+
el._html = function () {
|
|
214
|
+
this._attempts++;
|
|
215
|
+
return '<div>foo</div>';
|
|
216
|
+
};
|
|
217
|
+
const result = await toHaveHTML.call({}, el, ['div', '<div>foo</div>', 'toto'], {
|
|
218
|
+
replace: [[/Web/g, 'Browser']],
|
|
219
|
+
});
|
|
220
|
+
expect(result.pass).toBe(true);
|
|
221
|
+
expect(el._attempts).toBe(1);
|
|
222
|
+
});
|
|
223
|
+
test('success if array matches with html and multiple replacers and one of the replacers is a function', async () => {
|
|
224
|
+
const el = await $('sel');
|
|
225
|
+
el._attempts = 0;
|
|
226
|
+
el._html = function () {
|
|
227
|
+
this._attempts++;
|
|
228
|
+
return '<div>FOO</div>';
|
|
229
|
+
};
|
|
230
|
+
const result = await toHaveHTML.call({}, el, ['div', '<p>foo</p>', 'toto'], {
|
|
231
|
+
replace: [
|
|
232
|
+
[/div/g, 'p'],
|
|
233
|
+
[/[A-Z]/g, (match) => match.toLowerCase()],
|
|
234
|
+
],
|
|
235
|
+
});
|
|
236
|
+
expect(result.pass).toBe(true);
|
|
237
|
+
expect(el._attempts).toBe(1);
|
|
238
|
+
});
|
|
239
|
+
test('failure if array does not match with html', async () => {
|
|
240
|
+
const el = await $('sel');
|
|
241
|
+
el._attempts = 0;
|
|
242
|
+
el._html = function () {
|
|
243
|
+
this._attempts++;
|
|
244
|
+
return '<div>foo</div>';
|
|
245
|
+
};
|
|
246
|
+
const result = await toHaveHTML.call({}, el, ['div', 'foo'], { wait: 1 });
|
|
247
|
+
expect(result.pass).toBe(false);
|
|
248
|
+
expect(el._attempts).toBe(1);
|
|
249
|
+
});
|
|
250
|
+
describe('with RegExp', () => {
|
|
251
|
+
let el;
|
|
252
|
+
beforeEach(async () => {
|
|
253
|
+
el = await $('sel');
|
|
254
|
+
el._html = vi.fn().mockImplementation(() => {
|
|
255
|
+
return 'This is example HTML';
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
test('success if match', async () => {
|
|
259
|
+
const result = await toHaveHTML.call({}, el, /ExAmplE/i);
|
|
260
|
+
expect(result.pass).toBe(true);
|
|
261
|
+
});
|
|
262
|
+
test('success if array matches with RegExp', async () => {
|
|
263
|
+
const result = await toHaveHTML.call({}, el, ['div', /ExAmPlE/i]);
|
|
264
|
+
expect(result.pass).toBe(true);
|
|
265
|
+
});
|
|
266
|
+
test('success if array matches with html', async () => {
|
|
267
|
+
const result = await toHaveHTML.call({}, el, ['This is example HTML', /Webdriver/i]);
|
|
268
|
+
expect(result.pass).toBe(true);
|
|
269
|
+
});
|
|
270
|
+
test('success if array matches with html and ignoreCase', async () => {
|
|
271
|
+
const result = await toHaveHTML.call({}, el, ['ThIs Is ExAmPlE HTML', /Webdriver/i], {
|
|
272
|
+
ignoreCase: true,
|
|
273
|
+
});
|
|
274
|
+
expect(result.pass).toBe(true);
|
|
275
|
+
});
|
|
276
|
+
test('failure if no match', async () => {
|
|
277
|
+
const result = await toHaveHTML.call({}, el, /Webdriver/i);
|
|
278
|
+
expect(result.pass).toBe(false);
|
|
279
|
+
expect(getExpectMessage(result.message())).toContain('to have HTML');
|
|
280
|
+
expect(getExpected(result.message())).toContain('/Webdriver/i');
|
|
281
|
+
expect(getReceived(result.message())).toContain('This is example HTML');
|
|
282
|
+
});
|
|
283
|
+
test('failure if array does not match with html', async () => {
|
|
284
|
+
const result = await toHaveHTML.call({}, el, ['div', /Webdriver/i]);
|
|
285
|
+
expect(result.pass).toBe(false);
|
|
286
|
+
expect(getExpectMessage(result.message())).toContain('to have HTML');
|
|
287
|
+
expect(getExpected(result.message())).toContain('/Webdriver/i');
|
|
288
|
+
expect(getExpected(result.message())).toContain('div');
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
});
|