forked from DevExpress/testcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-controller.js
79 lines (66 loc) · 2.27 KB
/
test-controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const {
CLIENT_ERROR_MESSAGE,
CLIENT_PAGE_URL,
CLIENT_PAGE_URL_REGEXP,
SKIP_JS_ERRORS_CALLBACK_OPTIONS,
CLIENT_ERROR_REGEXP,
} = require('../constants');
fixture`TestController method`
.page('http://localhost:3000/fixtures/page-js-errors/pages/skip-js-errors.html');
test('Should skip JS errors with boolean param', async t => {
await t.skipJsErrors(true)
.click('button');
});
test('Should skip JS errors with multiple options', async t => {
await t.skipJsErrors({
message: CLIENT_ERROR_MESSAGE,
pageUrl: CLIENT_PAGE_URL,
})
.click('button');
});
test('Should skip JS errors with SkipJsErrorsCallbackOptions', async t => {
await t.skipJsErrors(SKIP_JS_ERRORS_CALLBACK_OPTIONS)
.click('button');
});
test('Should skip JS errors with callback function returning Promise', async t => {
const asyncFunc = () =>
new Promise(resolve => setTimeout(() => resolve(true), 3000));
await t.skipJsErrors(asyncFunc)
.click('button');
});
test('Should skip JS errors without param', async t => {
await t.skipJsErrors();
});
test('Should skip JS errors with SkipJsErrorsCallbackOptions containing RegExp enclosed in quotes', async t => {
await t.skipJsErrors({
message: `${ CLIENT_ERROR_REGEXP }`,
})
.click('button');
});
test('Should correctly skip JS errors with multiple method calls', async t => {
await t.skipJsErrors(true)
.click('button')
.skipJsErrors(false)
.click('button');
});
test('Should fail with SkipJsErrorsCallbackOptions', async t => {
const callbackOptions = {
fn: ({ message, pageUrl }) => message === CLIENT_ERROR_MESSAGE && pageUrl === 'incorrect url',
dependencies: { CLIENT_ERROR_MESSAGE },
};
await t.skipJsErrors(callbackOptions)
.click('button');
});
test("Should fail if message option doesn't satisfy the client error message", async t => {
await t.skipJsErrors({
message: /incorrect message/,
pageUrl: CLIENT_PAGE_URL_REGEXP,
})
.click('button');
});
test('Should fail due to error in callback function', async t => {
await t.skipJsErrors(() => {
throw new Error('Error in the skipJsError callback function');
})
.click('button');
});