How to use equalAssertBoolean method in Testcafe

Best JavaScript code snippet using testcafe

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

test-run-error-formatting-test.js

Source: test-run-error-formatting-test.js Github

copy
1const { assert, expect }                  = require('chai');
2const { pull: remove, chain, values }     = require('lodash');
3const TestRun                             = require('../../lib/test-run');
4const TEST_RUN_PHASE                      = require('../../lib/test-run/phase');
5const { TEST_RUN_ERRORS, RUNTIME_ERRORS } = require('../../lib/errors/types');
6const TestRunErrorFormattableAdapter      = require('../../lib/errors/test-run/formattable-adapter');
7const testCallsite                        = require('./data/test-callsite');
8const assertTestRunError                  = require('./helpers/assert-test-run-error');
9
10const {
11    AssertionExecutableArgumentError,
12    AssertionWithoutMethodCallError,
13    AssertionUnawaitedPromiseError,
14    ActionIntegerOptionError,
15    ActionPositiveIntegerOptionError,
16    ActionIntegerArgumentError,
17    ActionPositiveIntegerArgumentError,
18    ActionBooleanOptionError,
19    ActionBooleanArgumentError,
20    ActionSpeedOptionError,
21    ActionSelectorError,
22    ActionOptionsTypeError,
23    ActionStringArgumentError,
24    ActionNullableStringArgumentError,
25    ActionStringOrStringArrayArgumentError,
26    ActionStringArrayElementError,
27    ActionFunctionArgumentError,
28    PageLoadError,
29    UncaughtErrorOnPage,
30    UncaughtErrorInTestCode,
31    UncaughtErrorInClientFunctionCode,
32    UncaughtNonErrorObjectInTestCode,
33    UncaughtErrorInCustomDOMPropertyCode,
34    UnhandledPromiseRejectionError,
35    UncaughtExceptionError,
36    ActionElementNotFoundError,
37    ActionElementIsInvisibleError,
38    ActionSelectorMatchesWrongNodeTypeError,
39    ActionAdditionalElementNotFoundError,
40    ActionAdditionalElementIsInvisibleError,
41    ActionAdditionalSelectorMatchesWrongNodeTypeError,
42    ActionElementNonEditableError,
43    ActionElementNonContentEditableError,
44    ActionRootContainerNotFoundError,
45    ActionElementNotTextAreaError,
46    ActionIncorrectKeysError,
47    ActionCannotFindFileToUploadError,
48    ActionElementIsNotFileInputError,
49    ActionUnsupportedDeviceTypeError,
50    ActionInvalidScrollTargetError,
51    ClientFunctionExecutionInterruptionError,
52    ActionElementNotIframeError,
53    ActionIframeIsNotLoadedError,
54    CurrentIframeIsNotLoadedError,
55    CurrentIframeNotFoundError,
56    CurrentIframeIsInvisibleError,
57    MissingAwaitError,
58    ExternalAssertionLibraryError,
59    DomNodeClientFunctionResultError,
60    InvalidSelectorResultError,
61    NativeDialogNotHandledError,
62    UncaughtErrorInNativeDialogHandler,
63    SetNativeDialogHandlerCodeWrongTypeError,
64    CannotObtainInfoForElementSpecifiedBySelectorError,
65    WindowDimensionsOverflowError,
66    ForbiddenCharactersInScreenshotPathError,
67    InvalidElementScreenshotDimensionsError,
68    SetTestSpeedArgumentError,
69    RoleSwitchInRoleInitializerError,
70    ActionRoleArgumentError,
71    RequestHookNotImplementedMethodError,
72    RequestHookUnhandledError,
73    UncaughtErrorInCustomClientScriptCode,
74    UncaughtErrorInCustomClientScriptLoadedFromModule,
75    UncaughtErrorInCustomScript,
76    UncaughtTestCafeErrorInCustomScript,
77    ChildWindowIsNotLoadedError,
78    ChildWindowNotFoundError,
79    CannotSwitchToWindowError,
80    CloseChildWindowError,
81    ChildWindowClosedBeforeSwitchingError,
82    WindowNotFoundError,
83    ParentWindowNotFoundError,
84    PreviousWindowNotFoundError,
85    SwitchToWindowPredicateError,
86    CannotCloseWindowWithChildrenError,
87    MultipleWindowsModeIsDisabledError,
88    CannotCloseWindowWithoutParentError,
89    MultipleWindowsModeIsNotAvailableInRemoteBrowserError,
90    CannotRestoreChildWindowError,
91    TimeoutError,
92    ActionCookieArgumentError,
93    ActionCookieArgumentsError,
94    ActionUrlCookieArgumentError,
95    ActionUrlsCookieArgumentError,
96    ActionRequiredCookieArguments,
97    ActionStringOptionError,
98    ActionDateOptionError,
99    ActionNumberOptionError,
100} = require('../../lib/errors/test-run');
101
102const untestedErrorTypes = Object.keys(TEST_RUN_ERRORS).map(key => TEST_RUN_ERRORS[key]);
103
104const userAgentMock = 'Chrome 15.0.874.120 / macOS 10.15';
105
106function equalAssertArray () {
107    expect([1, 2, 3, [4, 5], 6]).eql([1, 4, 2, 3, [5, 6, [7]]]);
108}
109
110function equalAssertBoolean () {
111    expect(true).eql(false);
112}
113
114function equalAssertBuffer () {
115    expect(Buffer.from('test')).eql(Buffer.from([1, 2, 3]));
116}
117
118function equalAssertEmptyString () {
119    expect([]).eql('');
120}
121
122function equalAssertFunction () {
123    expect(function () {
124        return true;
125    }).eql(function () {
126        return false;
127    });
128}
129
130function equalAssertNumber () {
131    expect(1).eql(2);
132}
133
134function equalAssertObject () {
135    const obj1 = {
136        first: {
137            second: {
138                third: {
139                    fourth: {
140                        fifth: {
141                            hello: 'world',
142                            six:   '6',
143                        },
144                    },
145                },
146            },
147        },
148    };
149
150    const obj2 = {
151        first: {
152            second: {
153                third: {
154                    fourth: {
155                        fifth: {
156                            hello: 'world',
157                        },
158                    },
159                },
160            },
161        },
162    };
163
164    expect(obj1).eql(obj2);
165}
166
167function equalAssertString () {
168    expect('line1\nline2').eql('line1');
169}
170
171function equalAssertUndefinedNull () {
172    expect(void 0).eql(null);
173}
174
175function notEqualAssertString () {
176    assert.notEqual('foo', 'foo');
177}
178
179function okAssertBoolean () {
180    expect(false).ok;
181}
182
183function notOkAssertBoolean () {
184    expect(true).not.ok;
185}
186
187function containsAssertString () {
188    expect('foo').contains('bar');
189}
190
191function notContainsAssertString () {
192    expect('foobar').not.contains('bar');
193}
194
195function matchAssertRegExp () {
196    expect('some text').match(/some regexp/);
197}
198
199function notMatchAssertRegExp () {
200    expect('some text').not.match(/some \w+/);
201}
202
203function typeOfAssertNull () {
204    assert.typeOf(false, 'null');
205}
206
207function notTypeOfAssertNull () {
208    assert.notTypeOf(null, 'null');
209}
210
211function withinAssertNumber () {
212    expect(0).within(1, 2);
213}
214
215function notWithinAssertNumber () {
216    expect(0).not.within(0, 1);
217}
218
219function ltAssertNumber () {
220    expect(1).lt(0);
221}
222
223function lteAssertNumber () {
224    expect(1).lte(0);
225}
226
227function gtAssertNumber () {
228    expect(0).gt(1);
229}
230
231function gteAssertNumber () {
232    expect(0).gte(1);
233}
234
235const createAssertionError = fn => {
236    try {
237        fn();
238    }
239    catch (err) {
240        return err;
241    }
242
243    return null;
244};
245
246const ASSERT_ERRORS = {
247    equal: {
248        array:         createAssertionError(equalAssertArray),
249        boolean:       createAssertionError(equalAssertBoolean),
250        buffer:        createAssertionError(equalAssertBuffer),
251        emptyString:   createAssertionError(equalAssertEmptyString),
252        function:      createAssertionError(equalAssertFunction),
253        number:        createAssertionError(equalAssertNumber),
254        object:        createAssertionError(equalAssertObject),
255        string:        createAssertionError(equalAssertString),
256        undefinedNull: createAssertionError(equalAssertUndefinedNull),
257    },
258    notEqual:    { string: createAssertionError(notEqualAssertString) },
259    ok:          { boolean: createAssertionError(okAssertBoolean) },
260    notOk:       { boolean: createAssertionError(notOkAssertBoolean) },
261    contains:    { string: createAssertionError(containsAssertString) },
262    notContains: { string: createAssertionError(notContainsAssertString) },
263    match:       { regexp: createAssertionError(matchAssertRegExp) },
264    notMatch:    { regexp: createAssertionError(notMatchAssertRegExp) },
265    typeOf:      { null: createAssertionError(typeOfAssertNull) },
266    notTypeOf:   { null: createAssertionError(notTypeOfAssertNull) },
267    within:      { number: createAssertionError(withinAssertNumber) },
268    notWithin:   { number: createAssertionError(notWithinAssertNumber) },
269    lt:          { number: createAssertionError(ltAssertNumber) },
270    lte:         { number: createAssertionError(lteAssertNumber) },
271    gt:          { number: createAssertionError(gtAssertNumber) },
272    gte:         { number: createAssertionError(gteAssertNumber) },
273};
274
275const longSelector = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
276
277function getErrorAdapter (err) {
278    const screenshotPath = '/unix/path/with/<tag>';
279
280    return new TestRunErrorFormattableAdapter(err, {
281        userAgent:      userAgentMock,
282        screenshotPath: screenshotPath,
283        callsite:       testCallsite,
284        testRunPhase:   TEST_RUN_PHASE.initial,
285    });
286}
287
288function assertErrorMessage (file, err) {
289    assertTestRunError(err, '../data/expected-test-run-errors/' + file);
290
291    // NOTE: check that the list of error types contains an
292    // error of this type and remove tested messages from the list
293    expect(untestedErrorTypes.includes(err.code)).to.be.ok;
294    remove(untestedErrorTypes, err.code);
295}
296
297describe('Error formatting', () => {
298    describe('Errors', () => {
299        it('Base error formattable adapter properties', () => {
300            const testRunMock = TestRun.prototype;
301
302            testRunMock._ensureErrorId = err => {
303                err.id = 'error-id';
304            };
305
306            Object.assign(testRunMock, {
307                session:           { id: 'test-run-id' },
308                browserConnection: { userAgent: 'chrome' },
309                errScreenshotPath: 'screenshot-path',
310                phase:             'test-run-phase',
311                callsite:          'callsite',
312                errs:              [],
313            });
314
315            TestRun.prototype.addError.call(testRunMock, { callsite: 'callsite' });
316
317            const err = testRunMock.errs[0];
318
319            expect(err).instanceOf(TestRunErrorFormattableAdapter);
320
321            expect(err).eql({
322                userAgent:      'chrome',
323                screenshotPath: 'screenshot-path',
324                testRunId:      'test-run-id',
325                testRunPhase:   'test-run-phase',
326                callsite:       'callsite',
327                id:             'error-id',
328            });
329        });
330
331        it('Should not throw if the specified decorator was not found', () => {
332            expect(() => {
333                const error = new ExternalAssertionLibraryError(createAssertionError(equalAssertArray), testCallsite);
334
335                error.diff = '<div class="unknown-decorator">text</div>';
336
337                getErrorAdapter(error).formatMessage('', 100);
338            }).to.not.throw();
339        });
340
341        it('Should format "actionIntegerOptionError" message', () => {
342            assertErrorMessage('action-integer-option-error', new ActionIntegerOptionError('offsetX', '1.01'));
343        });
344
345        it('Should format "actionPositiveIntegerOptionError" message', () => {
346            assertErrorMessage('action-positive-integer-option-error', new ActionPositiveIntegerOptionError('caretPos', '-1'));
347        });
348
349        it('Should format "actionIntegerArgumentError" message', () => {
350            assertErrorMessage('action-integer-argument-error', new ActionIntegerArgumentError('dragOffsetX', 'NaN'));
351        });
352
353        it('Should format "actionPositiveIntegerArgumentError" message', () => {
354            assertErrorMessage('action-positive-integer-argument-error', new ActionPositiveIntegerArgumentError('startPos', '-1'));
355        });
356
357        it('Should format "actionBooleanOptionError" message', () => {
358            assertErrorMessage('action-boolean-option-error', new ActionBooleanOptionError('modifier.ctrl', 'object'));
359        });
360
361        it('Should format the "actionBooleanArgumentError" message', () => {
362            assertErrorMessage('action-boolean-argument-error', new ActionBooleanArgumentError('isAsyncExpression', 'object'));
363        });
364
365        it('Should format "actionSpeedOptionError" message', () => {
366            assertErrorMessage('action-speed-option-error', new ActionSpeedOptionError('speed', 'object'));
367        });
368
369        it('Should format "pageLoadError" message', () => {
370            assertErrorMessage('page-load-error', new PageLoadError('Failed to find a DNS-record for the resource', 'http://some-url.example.com'));
371        });
372
373        it('Should format "uncaughtErrorOnPage" message (with error stack)', () => {
374            const errStack = [
375                'Test error:',
376                '    at method3 (http://example.com):1:3',
377                '    at method2 (http://example.com):1:2',
378                '    at method1 (http://example.com):1:1',
379            ].join('\n');
380
381            assertErrorMessage('uncaught-js-error-on-page', new UncaughtErrorOnPage(errStack, 'http://example.org'));
382        });
383
384        it('Should format "uncaughtErrorInTestCode" message', () => {
385            assertErrorMessage('uncaught-js-error-in-test-code', new UncaughtErrorInTestCode(new Error('Custom script error'), testCallsite));
386        });
387
388        it('Should format "uncaughtNonErrorObjectInTestCode" message', () => {
389            assertErrorMessage('uncaught-non-error-object-in-test-code', new UncaughtNonErrorObjectInTestCode('Hey ya!'));
390        });
391
392        it('Should format "uncaughtErrorInAddCustomDOMProperties" message', () => {
393            assertErrorMessage('uncaught-error-in-add-custom-dom-properties-code', new UncaughtErrorInCustomDOMPropertyCode(testCallsite, new Error('Custom script error'), 'prop'));
394        });
395
396        it('Should format "unhandledPromiseRejectionError" message', () => {
397            assertErrorMessage('unhandled-promise-rejection-error', new UnhandledPromiseRejectionError('Hey ya!'));
398        });
399
400        it('Should format "uncaughtExceptionError" message', () => {
401            assertErrorMessage('uncaught-exception-error', new UncaughtExceptionError('Hey ya!'));
402        });
403
404        it('Should format "actionElementNotFoundError" message', () => {
405            assertErrorMessage('action-element-not-found-error', new ActionElementNotFoundError(null, {
406                apiFnChain: [longSelector, 'one', 'two', 'three'],
407                apiFnIndex: 1,
408            }));
409        });
410
411        it('Should format "actionElementIsInvisibleError" message', () => {
412            assertErrorMessage('action-element-is-invisible-error', new ActionElementIsInvisibleError());
413        });
414
415        it('Should format "actionSelectorMatchesWrongNodeTypeError" message', () => {
416            assertErrorMessage('action-selector-matches-wrong-node-type-error', new ActionSelectorMatchesWrongNodeTypeError('text'));
417        });
418
419        it('Should format "actionElementNonEditableError" message', () => {
420            assertErrorMessage('action-element-non-editable-error', new ActionElementNonEditableError());
421        });
422
423        it('Should format "actionRootContainerNotFoundError" message', () => {
424            assertErrorMessage('action-root-container-not-found-error', new ActionRootContainerNotFoundError());
425        });
426
427        it('Should format "actionElementNonContentEditableError" message', () => {
428            assertErrorMessage('action-element-non-content-editable-error', new ActionElementNonContentEditableError('startSelector'));
429        });
430
431        it('Should format "actionElementNotTextAreaError" message', () => {
432            assertErrorMessage('action-element-not-text-area-error', new ActionElementNotTextAreaError());
433        });
434
435        it('Should format "actionElementNotIframeError" message', () => {
436            assertErrorMessage('action-element-not-iframe-error', new ActionElementNotIframeError());
437        });
438
439        it('Should format "actionSelectorError" message', () => {
440            assertErrorMessage('action-selector-error', new ActionSelectorError('selector', { rawMessage: 'Yo!' }, true));
441        });
442
443        it('Should format "actionOptionsTypeError" message', () => {
444            assertErrorMessage('action-options-type-error', new ActionOptionsTypeError(typeof 1));
445        });
446
447        it('Should format "actionAdditionalElementNotFoundError" message', () => {
448            assertErrorMessage('action-additional-element-not-found-error', new ActionAdditionalElementNotFoundError('startSelector', {
449                apiFnChain: [longSelector, 'one', 'two', 'three'],
450                apiFnIndex: 1,
451            }));
452        });
453
454        it('Should format "actionAdditionalElementIsInvisibleError" message', () => {
455            assertErrorMessage('action-additional-element-is-invisible-error', new ActionAdditionalElementIsInvisibleError('startSelector'));
456        });
457
458        it('Should format "actionAdditionalSelectorMatchesWrongNodeTypeError" message', () => {
459            assertErrorMessage('action-additional-selector-matches-wrong-node-type-error', new ActionAdditionalSelectorMatchesWrongNodeTypeError('startSelector', 'text'));
460        });
461
462        it('Should format "actionStringArgumentError" message', () => {
463            assertErrorMessage('action-string-argument-error', new ActionStringArgumentError('text', typeof 1));
464        });
465
466        it('Should format "actionNullableStringArgumentError" message', () => {
467            assertErrorMessage('action-nullable-string-argument-error', new ActionNullableStringArgumentError('text', typeof 1));
468        });
469
470        it('Should format "actionIncorrectKeysError" message', () => {
471            assertErrorMessage('action-incorrect-keys-error', new ActionIncorrectKeysError('keys'));
472        });
473
474        it('Should format "actionNonEmptyStringArrayArgumentError" message', () => {
475            assertErrorMessage('action-non-empty-string-array-argument-error', new ActionStringOrStringArrayArgumentError('array', null));
476        });
477
478        it('Should format "actionStringArrayElementError" message', () => {
479            assertErrorMessage('action-string-array-element-error', new ActionStringArrayElementError('array', 'number', 1));
480        });
481
482        it('Should format "actionElementIsNotFileInputError" message', () => {
483            assertErrorMessage('action-element-is-not-file-input-error', new ActionElementIsNotFileInputError());
484        });
485
486        it('Should format "actionCannotFindFileToUploadError" message', () => {
487            const filePaths        = ['/path/1', '/path/2'];
488            const scannedFilepaths = ['full-path-to/path/1', 'full-path-to/path/2'];
489            const err              = new ActionCannotFindFileToUploadError(filePaths, scannedFilepaths);
490
491            assertErrorMessage('action-cannot-find-file-to-upload-error', err);
492        });
493
494        it('Should format "actionUnsupportedDeviceTypeError" message', () => {
495            assertErrorMessage('action-unsupported-device-type-error', new ActionUnsupportedDeviceTypeError('device', 'iPhone 555'));
496        });
497
498        it('Should format "actionInvalidScrollTargetError" message', () => {
499            assertErrorMessage('action-invalid-scroll-target-error', new ActionInvalidScrollTargetError(false, true));
500        });
501
502        it('Should format "actionIframeIsNotLoadedError" message', () => {
503            assertErrorMessage('action-iframe-is-not-loaded-error', new ActionIframeIsNotLoadedError());
504        });
505
506        it('Should format "currentIframeIsNotLoadedError" message', () => {
507            assertErrorMessage('current-iframe-is-not-loaded-error', new CurrentIframeIsNotLoadedError());
508        });
509
510        it('Should format "currentIframeNotFoundError" message', () => {
511            assertErrorMessage('current-iframe-not-found-error', new CurrentIframeNotFoundError());
512        });
513
514        it('Should format "currentIframeIsInvisibleError" message', () => {
515            assertErrorMessage('current-iframe-is-invisible-error', new CurrentIframeIsInvisibleError());
516        });
517
518        it('Should format "missingAwaitError"', () => {
519            assertErrorMessage('missing-await-error', new MissingAwaitError(testCallsite));
520        });
521
522        describe('Should format "externalAssertionLibraryError"', () => {
523            const filepath = function (assertion, filename) {
524                return `../data/expected-test-run-errors/external-assertion-library-errors/builtin/${assertion}/${filename}`;
525            };
526
527            it('Deep Equal', () => {
528                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.array, testCallsite), filepath('equal', 'array'));
529                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.boolean, testCallsite), filepath('equal', 'boolean'));
530                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.buffer, testCallsite), filepath('equal', 'buffer'));
531                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.emptyString, testCallsite), filepath('equal', 'empty-string'));
532                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.function, testCallsite), filepath('equal', 'function'));
533                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.number, testCallsite), filepath('equal', 'number'));
534                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.object, testCallsite), filepath('equal', 'object'));
535                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.string, testCallsite), filepath('equal', 'string'));
536
537                assertErrorMessage('external-assertion-library-errors/builtin/equal/undefined-null', new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.undefinedNull, testCallsite));
538            });
539
540            it('Not Deep Equal', () => {
541                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.notEqual.string, testCallsite), filepath('not-equal', 'string'));
542            });
543
544            it('Ok', () => {
545                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.ok.boolean, testCallsite), filepath('ok', 'boolean'));
546            });
547
548            it('Not Ok', () => {
549                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.notOk.boolean, testCallsite), filepath('not-ok', 'boolean'));
550            });
551
552            it('Contains', () => {
553                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.contains.string, testCallsite), filepath('contains', 'string'));
554            });
555
556            it('Not Contains', () => {
557                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.notContains.string, testCallsite), filepath('not-contains', 'string'));
558            });
559
560            it('Match', () => {
561                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.match.regexp, testCallsite), filepath('match', 'regexp'));
562            });
563
564            it('Not Match', () => {
565                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.notMatch.regexp, testCallsite), filepath('not-match', 'regexp'));
566            });
567
568            it('Type of', () => {
569                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.typeOf.null, testCallsite), filepath('type-of', 'null'));
570            });
571
572            it('Not Type of', () => {
573                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.notTypeOf.null, testCallsite), filepath('not-type-of', 'null'));
574            });
575
576            it('Within', () => {
577                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.within.number, testCallsite), filepath('within', 'number'));
578            });
579
580            it('Not Within', () => {
581                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.notWithin.number, testCallsite), filepath('not-within', 'number'));
582            });
583
584            it('Less than', () => {
585                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.lt.number, testCallsite), filepath('less-than', 'number'));
586            });
587
588            it('Less than or Equal to', () => {
589                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.lte.number, testCallsite), filepath('less-than-or-equal', 'number'));
590            });
591
592            it('Greater than', () => {
593                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.gt.number, testCallsite), filepath('greater-than', 'number'));
594            });
595
596            it('Greater than or Equal to', () => {
597                assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.gte.number, testCallsite), filepath('greater-than-or-equal', 'number'));
598            });
599        });
600
601        it('Should format "uncaughtErrorInClientFunctionCode"', () => {
602            assertErrorMessage('uncaught-error-in-client-function-code', new UncaughtErrorInClientFunctionCode('Selector', new Error('Some error.')));
603        });
604
605        it('Should format "clientFunctionExecutionInterruptionError"', () => {
606            assertErrorMessage('client-function-execution-interruption-error', new ClientFunctionExecutionInterruptionError('eval'));
607        });
608
609        it('Should format "domNodeClientFunctionResultError"', () => {
610            assertErrorMessage('dom-node-client-function-result-error', new DomNodeClientFunctionResultError('ClientFunction'));
611        });
612
613        it('Should format "invalidSelectorResultError"', () => {
614            assertErrorMessage('invalid-selector-result-error', new InvalidSelectorResultError());
615        });
616
617        it('Should format "nativeDialogNotHandledError"', () => {
618            assertErrorMessage('native-dialog-not-handled-error', new NativeDialogNotHandledError('alert', 'http://example.org'));
619        });
620
621        it('Should format "uncaughtErrorInNativeDialogHandler"', () => {
622            assertErrorMessage('uncaught-error-in-native-dialog-handler', new UncaughtErrorInNativeDialogHandler('alert', 'error message', 'http://example.org'));
623        });
624
625        it('Should format "setNativeDialogHandlerCodeWrongTypeError"', () => {
626            assertErrorMessage('set-native-dialog-handler-code-wrong-type-error', new SetNativeDialogHandlerCodeWrongTypeError('number'));
627        });
628
629        it('Should format "cannotObtainInfoForElementSpecifiedBySelectorError"', () => {
630            assertErrorMessage('cannot-obtain-info-for-element-specified-by-selector-error', new CannotObtainInfoForElementSpecifiedBySelectorError(testCallsite, {
631                apiFnChain: [longSelector, 'one', 'two', 'three'],
632                apiFnIndex: 1,
633            }));
634        });
635
636        it('Should format "windowDimensionsOverflowError"', () => {
637            assertErrorMessage('window-dimensions-overflow-error', new WindowDimensionsOverflowError());
638        });
639
640        it('Should format "forbiddenCharactersInScreenshotPathError"', () => {
641            assertErrorMessage('forbidden-characters-in-screenshot-path-error', new ForbiddenCharactersInScreenshotPathError('/root/bla:bla', [{
642                chars: ':',
643                index: 9,
644            }]));
645        });
646
647        it('Should format "invalidElementScreenshotDimensionsError"', () => {
648            assertErrorMessage('invalid-element-screenshot-dimensions-error', new InvalidElementScreenshotDimensionsError(0, 10));
649        });
650
651        it('Should format "setTestSpeedArgumentError"', () => {
652            assertErrorMessage('set-test-speed-argument-error', new SetTestSpeedArgumentError('speed', 'string'));
653        });
654
655        it('Should format "roleSwitchInRoleInitializerError"', () => {
656            assertErrorMessage('role-switch-in-role-initializer-error', new RoleSwitchInRoleInitializerError(testCallsite));
657        });
658
659        it('Should format "actionRoleArgumentError"', () => {
660            assertErrorMessage('action-role-argument-error', new ActionRoleArgumentError('role', 'number'));
661        });
662
663        it('Should format "assertionExecutableArgumentError"', () => {
664            assertErrorMessage('assertion-executable-argument-error', new AssertionExecutableArgumentError('actual', '1 + temp', { rawMessage: 'Unexpected identifier' }, true));
665        });
666
667        it('Should format "assertionWithoutMethodCallError"', () => {
668            assertErrorMessage('assertion-without-method-call-error', new AssertionWithoutMethodCallError(testCallsite));
669        });
670
671        it('Should format "assertionUnawaitedPromiseError"', () => {
672            assertErrorMessage('assertion-unawaited-promise-error', new AssertionUnawaitedPromiseError(testCallsite));
673        });
674
675        it('Should format "requestHookNotImplementedError"', () => {
676            assertErrorMessage('request-hook-method-not-implemented-error', new RequestHookNotImplementedMethodError('onRequest', 'MyHook'));
677        });
678
679        it('Should format "requestHookUnhandledError"', () => {
680            assertErrorMessage('request-hook-unhandled-error', new RequestHookUnhandledError(new Error('Test error'), 'MyHook', 'onRequest'));
681        });
682
683        it('Should format "uncaughtErrorInCustomClientScriptCode"', () => {
684            assertErrorMessage('uncaught-error-in-custom-client-script-code', new UncaughtErrorInCustomClientScriptCode(new TypeError('Cannot read property "prop" of undefined')));
685        });
686
687        it('Should format "uncaughtErrorInCustomClientScriptCodeLoadedFromModule"', () => {
688            assertErrorMessage('uncaught-error-in-custom-client-script-code-loaded-from-module', new UncaughtErrorInCustomClientScriptLoadedFromModule(new TypeError('Cannot read property "prop" of undefined'), 'test-module'));
689        });
690
691        it('Should format "uncaughtErrorInCustomScript"', () => {
692            assertErrorMessage('uncaught-error-in-custom-script', new UncaughtErrorInCustomScript(new Error('Test error'), '1+1', 1, 1, 'RAW API callsite'));
693        });
694
695        it('Should format "uncaughtTestCafeErrorInCustomScript"', () => {
696            const expression  = 'Hey ya!';
697            const originError = getErrorAdapter(new UncaughtNonErrorObjectInTestCode(expression));
698
699            assertErrorMessage('uncaught-test-cafe-error-in-custom-script', new UncaughtTestCafeErrorInCustomScript(originError, expression, void 0, void 0, 'RAW API callsite'));
700        });
701
702        it('Should format "childWindowIsNotLoadedError"', () => {
703            assertErrorMessage('child-window-is-not-loaded-error', new ChildWindowIsNotLoadedError());
704        });
705
706        it('Should format "childWindowNotFoundError"', () => {
707            assertErrorMessage('child-window-not-found-error', new ChildWindowNotFoundError());
708        });
709
710        it('Should format "cannotSwitchToWindowError"', () => {
711            assertErrorMessage('cannot-switch-to-child-window-error', new CannotSwitchToWindowError());
712        });
713
714        it('Should format "closeChildWindowError"', () => {
715            assertErrorMessage('close-child-window-error', new CloseChildWindowError());
716        });
717
718        it('Should format "childWindowClosedBeforeSwitchingError"', () => {
719            assertErrorMessage('child-window-closed-before-switching-error', new ChildWindowClosedBeforeSwitchingError());
720        });
721
722        it('Should format "cannotCloseWindowWithChildrenError"', () => {
723            assertErrorMessage('cannot-close-window-with-children-error', new CannotCloseWindowWithChildrenError());
724        });
725
726        it('Should format "cannotCloseWindowWithoutParentError"', () => {
727            assertErrorMessage('cannot-close-window-without-parent-error', new CannotCloseWindowWithoutParentError());
728        });
729
730        it('Should format "windowNotFoundError"', () => {
731            assertErrorMessage('window-not-found-error', new WindowNotFoundError());
732        });
733
734        it('Should format "parentWindowNotFoundError"', () => {
735            assertErrorMessage('parent-window-not-found-error', new ParentWindowNotFoundError());
736        });
737
738        it('Should format "previousWindowNotFoundError"', () => {
739            assertErrorMessage('previous-window-not-found-error', new PreviousWindowNotFoundError());
740        });
741
742        it('Should format "switchToWindowPredicateError"', () => {
743            assertErrorMessage('switch-to-window-predicate-error', new SwitchToWindowPredicateError('error message'));
744        });
745
746        it('Should format "actionFunctionArgumentError"', () => {
747            assertErrorMessage('action-function-argument-error', new ActionFunctionArgumentError('predicate', 'number'));
748        });
749
750        it('Should format "multipleWindowsModeIsDisabledError"', () => {
751            assertErrorMessage('multiple-windows-mode-is-disabled-error', new MultipleWindowsModeIsDisabledError('openWindow'));
752        });
753
754        it('Should format "multipleWindowsModeIsNotSupportedInRemoteBrowserError"', () => {
755            assertErrorMessage('multiple-windows-mode-is-not-available-in-remote-browser-error', new MultipleWindowsModeIsNotAvailableInRemoteBrowserError('openWindow'));
756        });
757
758        it('Should format "cannotRestoreChildWindowError"', () => {
759            assertErrorMessage('cannot-restore-child-window-error', new CannotRestoreChildWindowError());
760        });
761
762        it('Should format "executionTimeoutExceeded"', () => {
763            assertErrorMessage('execution-timeout-exceeded', new TimeoutError(500, 'Scope'));
764        });
765
766        it('Should format "actionCookieArgumentError"', () => {
767            assertErrorMessage('action-cookie-argument-error', new ActionCookieArgumentError());
768        });
769
770        it('Should format "actionCookieArgumentsError"', () => {
771            assertErrorMessage('action-cookie-arguments-error', new ActionCookieArgumentsError(0));
772        });
773
774        it('Should format "ActionUrlCookieArgumentError"', () => {
775            assertErrorMessage('action-url-cookie-argument-error', new ActionUrlCookieArgumentError());
776        });
777
778        it('Should format "ActionUrlsCookieArgumentError"', () => {
779            assertErrorMessage('action-urls-cookie-argument-error', new ActionUrlsCookieArgumentError(0));
780        });
781
782        it('Should format "actionRequiredSetCookieArgumentsAreMissedError"', () => {
783            assertErrorMessage('action-required-cookie-arguments', new ActionRequiredCookieArguments());
784        });
785
786        it('Should format "actionStringOptionError"', () => {
787            assertErrorMessage('action-string-option-error', new ActionStringOptionError('name', 'object'));
788        });
789
790        it('Should format "actionExpiresOptionError"', () => {
791            assertErrorMessage('action-date-option-error', new ActionDateOptionError('expires', 'string'));
792        });
793
794        it('Should format "actionNumberOptionError"', () => {
795            assertErrorMessage('action-number-option-error', new ActionNumberOptionError('maxAge', 'object'));
796        });
797    });
798
799    describe('Test coverage', () => {
800        it('Should test messages for all error codes', () => {
801            expect(untestedErrorTypes).to.be.empty;
802        });
803
804        it('Errors codes should be unique', () => {
805            function getDuplicates (codes) {
806                return chain(codes).groupBy().pickBy(x => x.length > 1).keys().value();
807            }
808
809            const testRunErrorCodes                    = values(TEST_RUN_ERRORS);
810            const runtimeErrorCodes                    = values(RUNTIME_ERRORS);
811            const testRunErrorCodeDuplicates           = getDuplicates(testRunErrorCodes);
812            const runtimeErrorCodeDuplicates           = getDuplicates(runtimeErrorCodes);
813            const testRunAndRuntimeErrorCodeDuplicates = getDuplicates(testRunErrorCodes.concat(runtimeErrorCodes));
814
815            expect(testRunErrorCodeDuplicates, 'TestRunErrorCode duplicates').to.be.empty;
816            expect(runtimeErrorCodeDuplicates, 'RuntimeErrorCode duplicates').to.be.empty;
817            expect(testRunAndRuntimeErrorCodeDuplicates, 'Intersections between TestRunErrorCodes and RuntimeErrorCodes').to.be.empty;
818        });
819    });
820});
821
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Testcafe on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)