/
error_messages.ts
2284 lines (1905 loc) · 87.4 KB
/
error_messages.ts
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import _ from 'lodash'
import { stripIndent } from 'common-tags'
import capitalize from 'underscore.string/capitalize'
import $stackUtils from './stack_utils'
const divider = (num, char) => {
return Array(num).join(char)
}
const format = (data) => {
if (_.isString(data)) {
return _.truncate(data, { length: 2000 })
}
if (_.isObject(data)) {
return JSON.stringify(data, null, 2)
}
return data
}
const formatConfigFile = (configFile) => {
if (configFile === false) {
return '`cypress.json` (currently disabled by --config-file=false)'
}
return `\`${format(configFile)}\``
}
const formatRedirects = (redirects = [], listIndentSize) => {
return _.map(redirects, (redirect) => {
return `${' '.repeat(listIndentSize)} - ${redirect}`
})
}
const formatProp = (memo, field): string[] => {
const { key, value } = field
if (value != null) {
memo.push(`${capitalize(key)}: ${format(value)}`)
}
return memo
}
const cmd = (command, args = '') => {
const prefix = command.startsWith('Cypress') ? '' : 'cy.'
return `\`${prefix}${command}(${args})\``
}
const getScreenshotDocsPath = (cmd) => {
if (cmd === 'Cypress.Screenshot.defaults') {
return 'screenshot-api'
}
return 'screenshot'
}
const getRedirects = (obj, phrase, listIndentSize) => {
const redirects = obj.redirects ?? []
if (!redirects.length) {
return ''
}
const word = redirects.length > 1 ? 'times' : 'time'
const list = formatRedirects(redirects, listIndentSize)
return [
`${phrase} '${redirects.length}' ${word} to:`,
'',
`${list.join('\n')}`,
].join('\n')
}
const getHttpProps = (fields: { value: string, key: string }[] = []) => {
return _
.chain(fields)
.reduce<string[]>(formatProp, [])
.join('\n')
.value()
}
// When a function that returns a multi-line string like getHttpProps()
// is used inside a template string(``) & stripIndent tag,
// the returned string doesn't respect the parent indent.
// It prevents `stripIndent` from stripping indent correctly.
// To avoid this problem, we need to manually set the indent size to be stripped.
//
// cyStripIndent strips the indent in a line if it begins with that indent size or bigger.
// If not, it ignores the line.
const cyStripIndent = (str, indentSize) => {
const indent = ' '.repeat(indentSize)
return str.split('\n').map((s) => {
return s.startsWith(indent)
? s.substring(indentSize)
: s
}).join('\n')
}
export default {
add: {
type_missing: '`Cypress.add(key, fn, type)` must include a type!',
},
alias: {
invalid: 'Invalid alias: `{{name}}`.\nYou forgot the `@`. It should be written as: `@{{displayName}}`.',
not_registered_with_available: `${cmd('{{cmd}}')} could not find a registered alias for: \`@{{displayName}}\`.\nAvailable aliases are: \`{{availableAliases}}\`.`,
not_registered_without_available: `${cmd('{{cmd}}')} could not find a registered alias for: \`@{{displayName}}\`.\nYou have not aliased anything yet.`,
},
as: {
docsUrl: 'https://on.cypress.io/as',
empty_string: {
message: `${cmd('as')} cannot be passed an empty string.`,
},
invalid_type: {
message: `${cmd('as')} can only accept a string.`,
},
invalid_first_token: {
message: '`{{alias}}` cannot be named starting with the `@` symbol. Try renaming the alias to `{{suggestedName}}`, or something else that does not start with the `@` symbol.',
},
reserved_word: {
message: `${cmd('as')} cannot be aliased as: \`{{alias}}\`. This word is reserved.`,
},
},
selectFile: {
docsUrl: 'https://on.cypress.io/selectfile',
invalid_action: {
message: `${cmd('selectFile')} \`action\` can only be \`select\` or \`drag-drop\`. You passed: \`{{action}}\`.`,
},
invalid_array_file_reference: {
message: `${cmd('selectFile')} must be passed an array of Buffers or objects with non-null \`contents\`. At files[{{index}}] you passed: \`{{file}}\`.`,
},
invalid_single_file_reference: {
message: `${cmd('selectFile')} must be passed a Buffer or an object with a non-null \`contents\` property as its 1st argument. You passed: \`{{file}}\`.`,
},
multiple_elements: {
message: `${cmd('selectFile')} can only be called on a single element. Your subject contained {{num}} elements.`,
},
not_file_input: {
message: `${cmd('selectFile')} can only be called on an \`<input type="file">\` or a \`<label for="fileInput">\` pointing to or containing one. Your subject is: \`{{node}}\`.`,
},
invalid_alias: {
message: `${cmd('selectFile')} can only attach strings, Buffers or objects, while your alias \`{{alias}}\` resolved to: \`{{subject}}\`.`,
},
},
blur: {
docsUrl: 'https://on.cypress.io/blur',
multiple_elements: {
message: `${cmd('blur')} can only be called on a single element. Your subject contained {{num}} elements.`,
},
no_focused_element: {
message: `${cmd('blur')} can only be called when there is a currently focused element.`,
},
timed_out: {
message: `${cmd('blur')} timed out because your browser did not receive any \`blur\` events. This is a known bug in Chrome when it is not the currently focused window.`,
},
wrong_focused_element: {
message: `${cmd('blur')} can only be called on the focused element. Currently the focused element is a: \`{{node}}\``,
},
},
browser: {
invalid_arg: '{{prefix}} must be passed a string, object, or an array. You passed: `{{obj}}`',
},
chai: {
length_invalid_argument: 'You must provide a valid number to a `length` assertion. You passed: `{{length}}`',
match_invalid_argument: '`match` requires its argument be a `RegExp`. You passed: `{{regExp}}`',
invalid_jquery_obj (obj) {
return stripIndent`\
You attempted to make a chai-jQuery assertion on an object that is neither a DOM object or a jQuery object.
The chai-jQuery assertion you used was:
> ${obj.assertion}
The invalid subject you asserted on was:
> ${obj.subject}
To use chai-jQuery assertions your subject must be valid.
This can sometimes happen if a previous assertion changed the subject.`
},
},
check_uncheck: {
invalid_element: {
message: `${cmd('{{cmd}}')} can only be called on \`:checkbox\`{{phrase}}. Your subject {{word}} a: \`{{node}}\``,
docsUrl: 'https://on.cypress.io/{{cmd}}',
},
element_missing_value_attribute: {
message: `{{node}} cannot be checked/unchecked because it has no \`value\` attribute and ${cmd('{{cmd}}')} was supplied a value argument`,
docsUrl: 'https://on.cypress.io/{{cmd}}',
},
},
clear: {
invalid_element: {
message: stripIndent`\
${cmd('clear')} failed because it requires a valid clearable element.
The element cleared was:
> \`{{node}}\`
A clearable element matches one of the following selectors:
'a[href]'
'area[href]'
'input'
'select'
'textarea'
'button'
'iframe'
'[tabindex]'
'[contenteditable]'`,
docsUrl: 'https://on.cypress.io/clear',
},
},
clearCookie: {
invalid_argument: {
message: `${cmd('clearCookie')} must be passed a string argument for name.`,
docsUrl: 'https://on.cypress.io/clearcookie',
},
},
clearLocalStorage: {
invalid_argument: {
message: `${cmd('clearLocalStorage')} must be called with either a string or regular expression.`,
docsUrl: 'https://on.cypress.io/clearlocalstorage',
},
},
click: {
multiple_elements: {
message: `${cmd('{{cmd}}')} can only be called on a single element. Your subject contained {{num}} elements. Pass \`{ multiple: true }\` if you want to serially click each element.`,
docsUrl: 'https://on.cypress.io/click',
},
on_select_element: {
message: `${cmd('{{cmd}}')} cannot be called on a \`<select>\` element. Use ${cmd('select')} command instead to change the value.`,
docsUrl: 'https://on.cypress.io/select',
},
},
clock: {
invalid_1st_arg: {
message: `${cmd('clock')} only accepts a number or an \`options\` object for its first argument. You passed: \`{{arg}}\``,
docsUrl: 'https://on.cypress.io/clock',
},
invalid_2nd_arg: {
message: `${cmd('clock')} only accepts an array of function names or an \`options\` object for its second argument. You passed: \`{{arg}}\``,
docsUrl: 'https://on.cypress.io/clock',
},
},
config: {
invalid_argument: {
message: `Setting the config via ${cmd('Cypress.config')} failed with the following validation error:\n\n{{errMsg}}`,
docsUrl: 'https://on.cypress.io/config',
},
invalid_test_override: {
message: `The config override passed to your test has the following validation error:\n\n{{errMsg}}`,
docsUrl: 'https://on.cypress.io/config',
},
invalid_cypress_config_override: {
message: `\`Cypress.config()\` cannot mutate option \`{{errProperty}}\` because it is a read-only property.`,
},
invalid_test_config_override: {
message: `Cypress test configuration cannot mutate option \`{{errProperty}}\` because it is a read-only property.`,
},
},
contains: {
empty_string: {
message: `${cmd('contains')} cannot be passed an empty string.`,
docsUrl: 'https://on.cypress.io/contains',
},
invalid_argument: {
message: `${cmd('contains')} can only accept a string, number or regular expression.`,
docsUrl: 'https://on.cypress.io/contains',
},
length_option: {
message: `${cmd('contains')} cannot be passed a \`length\` option because it will only ever return 1 element.`,
docsUrl: 'https://on.cypress.io/contains',
},
regex_conflict: {
message: `You passed a regular expression with the case-insensitive (_i_) flag and \`{ matchCase: true }\` to ${cmd('contains')}. Those options conflict with each other, so please choose one or the other.`,
docsUrl: 'https://on.cypress.io/contains',
},
},
cookies: {
backend_error (obj) {
return {
message: [
`${cmd('{{cmd}}')} had an unexpected error {{action}} {{browserDisplayName}}.`,
``,
`> {{error}}`,
``,
].join('\n'),
docsUrl: `https://on.cypress.io/${_.toLower(obj.cmd)}`,
}
},
invalid_name (obj) {
return {
message: `${cmd('{{cmd}}')} must be passed an RFC-6265-compliant cookie name. You passed:\n\n\`{{name}}\``,
docsUrl: `https://on.cypress.io/${_.toLower(obj.cmd)}`,
}
},
timed_out (obj) {
return {
message: `${cmd('{{cmd}}')} timed out waiting \`{{timeout}}ms\` to complete.`,
docsUrl: `https://on.cypress.io/${_.toLower(obj.cmd)}`,
}
},
whitelist_renamed (obj) {
return {
message: `\`${obj.type}\` \`whitelist\` option has been renamed to \`preserve\`. Please rename \`whitelist\` to \`preserve\`.`,
}
},
},
dom: {
actionability_failed: stripIndent`
${cmd('{{cmd}}')} could not be issued because we could not determine the actionability of this element:
\`{{node}}\`
You can prevent this by passing \`{force: true}\` to disable all error checking.
`,
animating: {
message: stripIndent`\
${cmd('{{cmd}}')} could not be issued because this element is currently animating:
\`{{node}}\`
You can fix this problem by:
- Passing \`{force: true}\` which disables all error checking
- Passing \`{waitForAnimations: false}\` which disables waiting on animations
- Passing \`{animationDistanceThreshold: 20}\` which decreases the sensitivity`,
docsUrl: 'https://on.cypress.io/element-is-animating',
},
animation_check_failed: 'Not enough coord points provided to calculate distance.',
center_hidden: {
message: stripIndent`\
${cmd('{{cmd}}')} failed because the center of this element is hidden from view:
\`{{node}}\`
Fix this problem, or use \`{force: true}\` to disable error checking.`,
docsUrl: 'https://on.cypress.io/element-cannot-be-interacted-with',
},
covered: {
message: stripIndent`\
${cmd('{{cmd}}')} failed because this element:
\`{{element1}}\`
is being covered by another element:
\`{{element2}}\`
Fix this problem, or use {force: true} to disable error checking.`,
docsUrl: 'https://on.cypress.io/element-cannot-be-interacted-with',
},
pointer_events_none (obj) {
return {
message: stripIndent`\
${cmd(obj.cmd)} failed because this element:
\`${obj.element}\`
has CSS \`pointer-events: none\`${obj.elementInherited ? `, inherited from this element:\n\n\`${obj.elementInherited}\`\n` : ''}
\`pointer-events: none\` prevents user mouse interaction.
Fix this problem, or use {force: true} to disable error checking.`,
docsUrl: 'https://on.cypress.io/element-cannot-be-interacted-with',
}
},
disabled: {
message: stripIndent`\
${cmd('{{cmd}}')} failed because this element is \`disabled\`:
\`{{node}}\`
Fix this problem, or use \`{force: true}\` to disable error checking.`,
docsUrl: 'https://on.cypress.io/element-cannot-be-interacted-with',
},
invalid_position_argument: {
message: 'Invalid position argument: `{{position}}`. Position may only be {{validPositions}}.',
docsUrl: 'https://on.cypress.io/element-cannot-be-interacted-with',
},
not_scrollable: {
message: stripIndent`\
${cmd('{{cmd}}')} failed because this element is not scrollable:
\`{{node}}\`
Make sure you're targeting the correct element or use \`{ensureScrollable: false}\` to disable the scrollable check.`,
docsUrl: 'https://on.cypress.io/scrollto',
},
not_visible: {
message: stripIndent`\
${cmd('{{cmd}}')} failed because this element is not visible:
\`{{node}}\`
{{reason}}
Fix this problem, or use \`{force: true}\` to disable error checking.`,
docsUrl: 'https://on.cypress.io/element-cannot-be-interacted-with',
},
readonly: {
message: stripIndent`\
${cmd('{{cmd}}')} failed because this element is readonly:
\`{{node}}\`
Fix this problem, or use \`{force: true}\` to disable error checking.`,
docsUrl: 'https://on.cypress.io/element-cannot-be-interacted-with',
},
},
each: {
invalid_argument: {
message: `${cmd('each')} must be passed a callback function.`,
docsUrl: 'https://on.cypress.io/each',
},
non_array: {
message: `${cmd('each')} can only operate on an array like subject. Your subject was: \`{{subject}}\``,
docsUrl: 'https://on.cypress.io/each',
},
},
exec: {
failed: {
message: stripIndent`
${cmd('exec', '\'{{cmd}}\'')} failed with the following error:
> "{{error}}"`,
docsUrl: 'https://on.cypress.io/exec',
},
invalid_argument: {
message: `${cmd('exec')} must be passed a non-empty string as its 1st argument. You passed: '{{cmd}}'.`,
docsUrl: 'https://on.cypress.io/exec',
},
non_zero_exit: {
message: stripIndent`\
${cmd('exec', '\'{{cmd}}\'')} failed because the command exited with a non-zero code.
Pass \`{failOnNonZeroExit: false}\` to ignore exit code failures.
Information about the failure:
Code: {{code}}
{{output}}`,
docsUrl: 'https://on.cypress.io/exec',
},
timed_out: {
message: `${cmd('exec', '\'{{cmd}}\'')} timed out after waiting \`{{timeout}}ms\`.`,
docsUrl: 'https://on.cypress.io/exec',
},
},
files: {
unexpected_error (obj) {
return {
message: stripIndent`
${cmd('{{cmd}}', '"{{file}}"')} failed while trying to {{action}} the file at the following path:
\`{{filePath}}\`
The following error occurred:
> "{{error}}"`,
docsUrl: `https://on.cypress.io/${_.toLower(obj.cmd)}`,
}
},
existent (obj) {
return {
message: stripIndent`
${cmd('{{cmd}}', '"{{file}}"')} failed because the file exists when expected not to exist at the following path:
\`{{filePath}}\``,
docsUrl: `https://on.cypress.io/${_.toLower(obj.cmd)}`,
}
},
invalid_argument (obj) {
return {
message: `${cmd('{{cmd}}')} must be passed a non-empty string as its 1st argument. You passed: \`{{file}}\`.`,
docsUrl: `https://on.cypress.io/${_.toLower(obj.cmd)}`,
}
},
invalid_contents: {
message: `${cmd('writeFile')} must be passed a non-empty string, an object, or an array as its 2nd argument. You passed: \`{{contents}}\`.`,
docsUrl: 'https://on.cypress.io/writefile',
},
nonexistent (obj) {
return {
message: stripIndent`
${cmd('{{cmd}}', '"{{file}}"')} failed because the file does not exist at the following path:
\`{{filePath}}\``,
docsUrl: `https://on.cypress.io/${_.toLower(obj.cmd)}`,
}
},
timed_out (obj) {
return {
message: `${cmd('{{cmd}}', '"{{file}}"')} timed out after waiting \`{{timeout}}ms\`.`,
docsUrl: `https://on.cypress.io/${_.toLower(obj.cmd)}`,
}
},
},
fixture: {
set_to_false: {
message: `${cmd('fixture')} is not valid because you have configured \`fixturesFolder\` to \`false\`.`,
docsUrl: 'https://on.cypress.io/fixture',
},
timed_out: {
message: `${cmd('fixture')} timed out waiting \`{{timeout}}ms\` to receive a fixture. No fixture was ever sent by the server.`,
docsUrl: 'https://on.cypress.io/fixture',
},
},
focus: {
invalid_element: {
message: `${cmd('focus')} can only be called on a valid focusable element. Your subject is a: \`{{node}}\``,
docsUrl: 'https://on.cypress.io/focus',
},
multiple_elements: {
message: `${cmd('focus')} can only be called on a single element. Your subject contained {{num}} elements.`,
docsUrl: 'https://on.cypress.io/focus',
},
timed_out: {
message: `${cmd('focus')} timed out because your browser did not receive any \`focus\` events. This is a known bug in Chrome when it is not the currently focused window.`,
docsUrl: 'https://on.cypress.io/focus',
},
},
get: {
alias_invalid: {
message: '`{{prop}}` is not a valid alias property. Only `numbers` or `all` is permitted.',
docsUrl: 'https://on.cypress.io/get',
},
alias_zero: {
message: '`0` is not a valid alias property. Are you trying to ask for the first response? If so write `@{{alias}}.1`',
docsUrl: 'https://on.cypress.io/get',
},
invalid_options: {
message: `${cmd('get')} only accepts an options object for its second argument. You passed {{options}}`,
docsUrl: 'https://on.cypress.io/get',
},
},
getCookie: {
invalid_argument: {
message: `${cmd('getCookie')} must be passed a string argument for name.`,
docsUrl: 'https://on.cypress.io/getcookie',
},
},
go: {
invalid_argument: {
message: `${cmd('go')} accepts only a string or number argument`,
docsUrl: 'https://on.cypress.io/go',
},
invalid_direction: {
message: `${cmd('go')} accepts either \`forward\` or \`back\`. You passed: \`{{str}}\``,
docsUrl: 'https://on.cypress.io/go',
},
invalid_number: {
message: `${cmd('go')} cannot accept \`0\`. The number must be greater or less than \`0\`.`,
docsUrl: 'https://on.cypress.io/go',
},
},
group: {
missing_fn: '`group` API must be called with a function.',
},
hover: {
not_implemented: {
message: [
`${cmd('hover')} is not currently implemented.`,
'However it is usually easy to workaround.',
'Read the following document for a detailed explanation.',
].join('\n'),
docsUrl: 'https://on.cypress.io/hover',
},
},
invoke: {
prop_not_a_function: {
message: stripIndent`\
${cmd('invoke')} errored because the property: \`{{prop}}\` returned a \`{{type}}\` value instead of a function. ${cmd('invoke')} can only be used on properties that return callable functions.
${cmd('invoke')} waited for the specified property \`{{prop}}\` to return a function, but it never did.
If you want to assert on the property's value, then switch to use ${cmd('its')} and add an assertion such as:
\`cy.wrap({ foo: 'bar' }).its('foo').should('eq', 'bar')\``,
docsUrl: 'https://on.cypress.io/invoke',
},
subject_null_or_undefined: {
message: stripIndent`\
${cmd('invoke')} errored because your subject is: \`{{value}}\`. You cannot invoke any functions such as \`{{prop}}\` on a \`{{value}}\` value.
If you expect your subject to be \`{{value}}\`, then add an assertion such as:
\`cy.wrap({{value}}).should('be.{{value}}')\``,
docsUrl: 'https://on.cypress.io/invoke',
},
null_or_undefined_prop_value: {
message: stripIndent`\
${cmd('invoke')} errored because the property: \`{{prop}}\` is not a function, and instead returned a \`{{value}}\` value.
${cmd('invoke')} waited for the specified property \`{{prop}}\` to become a callable function, but it never did.
If you expect the property \`{{prop}}\` to be \`{{value}}\`, then switch to use ${cmd('its')} and add an assertion such as:
\`cy.wrap({ foo: {{value}} }).its('foo').should('be.{{value}}')\``,
docsUrl: 'https://on.cypress.io/invoke',
},
},
its: {
subject_null_or_undefined: {
message: stripIndent`\
${cmd('its')} errored because your subject is: \`{{value}}\`. You cannot access any properties such as \`{{prop}}\` on a \`{{value}}\` value.
If you expect your subject to be \`{{value}}\`, then add an assertion such as:
\`cy.wrap({{value}}).should('be.{{value}}')\``,
docsUrl: 'https://on.cypress.io/its',
},
null_or_undefined_prop_value: {
message: stripIndent`\
${cmd('its')} errored because the property: \`{{prop}}\` returned a \`{{value}}\` value.
${cmd('its')} waited for the specified property \`{{prop}}\` to become accessible, but it never did.
If you expect the property \`{{prop}}\` to be \`{{value}}\`, then add an assertion such as:
\`cy.wrap({ foo: {{value}} }).its('foo').should('be.{{value}}')\``,
docsUrl: 'https://on.cypress.io/its',
},
},
invoke_its: {
nonexistent_prop: {
message: stripIndent`\
${cmd('{{cmd}}')} errored because the property: \`{{prop}}\` does not exist on your subject.
${cmd('{{cmd}}')} waited for the specified property \`{{prop}}\` to exist, but it never did.
If you do not expect the property \`{{prop}}\` to exist, then add an assertion such as:
\`cy.wrap({ foo: 'bar' }).its('quux').should('not.exist')\``,
docsUrl: 'https://on.cypress.io/{{cmd}}',
},
previous_prop_null_or_undefined: {
message: stripIndent`\
${cmd('{{cmd}}')} errored because the property: \`{{previousProp}}\` returned a \`{{value}}\` value. The property: \`{{prop}}\` does not exist on a \`{{value}}\` value.
${cmd('{{cmd}}')} waited for the specified property \`{{prop}}\` to become accessible, but it never did.
If you do not expect the property \`{{prop}}\` to exist, then add an assertion such as:
\`cy.wrap({ foo: {{value}} }).its('foo.baz').should('not.exist')\``,
docsUrl: 'https://on.cypress.io/{{cmd}}',
},
invalid_1st_arg: {
message: `${cmd('{{cmd}}')} only accepts a string as the first argument.`,
docsUrl: 'https://on.cypress.io/{{cmd}}',
},
invalid_num_of_args: {
message: stripIndent`\
${cmd('{{cmd}}')} does not accept additional arguments.
If you want to invoke a function with arguments, use \`.invoke()\`.`,
docsUrl: 'https://on.cypress.io/{{cmd}}',
},
invalid_options_arg: {
message: `${cmd('{{cmd}}')} only accepts an object as the options argument.`,
docsUrl: 'https://on.cypress.io/{{cmd}}',
},
invalid_prop_name_arg: {
message: `${cmd('{{cmd}}')} only accepts a string or a number as the {{identifier}}Name argument.`,
docsUrl: 'https://on.cypress.io/{{cmd}}',
},
null_or_undefined_property_name: {
message: `${cmd('{{cmd}}')} expects the {{identifier}}Name argument to have a value.`,
docsUrl: 'https://on.cypress.io/{{cmd}}',
},
timed_out: {
message: stripIndent`\
${cmd('{{cmd}}')} timed out after waiting \`{{timeout}}ms\`.
Your callback function returned a promise that never resolved.
The callback function was:
{{func}}`,
docsUrl: 'https://on.cypress.io/{{cmd}}',
},
},
keyboard: {
invalid_arg: {
message: `${cmd('Cypress.Keyboard.defaults')} must be called with an object. You passed: \`{{arg}}\``,
docsUrl: 'https://on.cypress.io/keyboard-api',
},
invalid_delay ({ cmd: command, option, delay, docsPath }) {
return {
message: `${cmd(command)} \`${option}\` option must be 0 (zero) or a positive number. You passed: \`${delay}\``,
docsUrl: `https://on.cypress.io/${docsPath}`,
}
},
invalid_per_test_delay: {
message: `The test configuration \`keystrokeDelay\` option must be 0 (zero) or a positive number. You passed: \`{{delay}}\``,
docsUrl: 'https://on.cypress.io/test-configuration',
},
},
location: {
invalid_key: {
message: 'Location object does not have key: `{{key}}`',
docsUrl: 'https://on.cypress.io/location',
},
},
log: {
invalid_argument: {
message: '`Cypress.log()` can only be called with an options object. Your argument was: `{{arg}}`',
docsUrl: 'https://on.cypress.io/cypress-log',
},
},
miscellaneous: {
returned_value_and_commands_from_custom_command (obj) {
return {
message: stripIndent`\
Cypress detected that you invoked one or more cy commands in a custom command but returned a different value.
The custom command was:
> ${cmd(obj.current)}
The return value was:
> {{returned}}
Because cy commands are asynchronous and are queued to be run later, it doesn't make sense to return anything else.
For convenience, you can also simply omit any return value or return \`undefined\` and Cypress will not error.
In previous versions of Cypress we automatically detected this and forced the cy commands to be returned. To make things less magical and clearer, we are now throwing an error.`
// since obj.returned can be multi-lined, it can mess up stripIndent, so we replace it after
.replace('{{returned}}', obj.returned),
docsUrl: 'https://on.cypress.io/returning-value-and-commands-in-custom-command',
}
},
returned_value_and_commands (obj) {
return {
message: stripIndent`\
Cypress detected that you invoked one or more cy commands but returned a different value.
The return value was:
> {{returned}}
Because cy commands are asynchronous and are queued to be run later, it doesn't make sense to return anything else.
For convenience, you can also simply omit any return value or return \`undefined\` and Cypress will not error.
In previous versions of Cypress we automatically detected this and forced the cy commands to be returned. To make things less magical and clearer, we are now throwing an error.`
// since obj.returned can be multi-lined, it can mess up stripIndent, so we replace it after
.replace('{{returned}}', obj.returned),
docsUrl: 'https://on.cypress.io/returning-value-and-commands-in-test',
}
},
command_returned_promise_and_commands (obj) {
return {
message: stripIndent`\
Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.
The command that returned the promise was:
> ${cmd(obj.current)}
The cy command you invoked inside the promise was:
> ${cmd(obj.called)}
Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise.
Cypress will resolve your command with whatever the final Cypress command yields.
The reason this is an error instead of a warning is because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked. Attempting to reconcile this would prevent Cypress from ever resolving.`,
docsUrl: 'https://on.cypress.io/returning-promise-and-commands-in-another-command',
}
},
mixing_promises_and_commands (obj) {
return {
message: stripIndent`\
Cypress detected that you returned a promise in a test, but also invoked one or more cy commands inside of that promise.
The test title was:
> ${obj.title}
While this works in practice, it's often indicative of an anti-pattern. You almost never need to return both a promise and also invoke cy commands.
Cy commands themselves are already promise like, and you can likely avoid the use of the separate Promise.`,
docsUrl: 'https://on.cypress.io/returning-promise-and-commands-in-test',
}
},
dangling_commands: {
message: stripIndent`\
Oops, Cypress detected something wrong with your test code.
The test has finished but Cypress still has commands in its queue.
The {{numCommands}} queued commands that have not yet run are:
{{commands}}
In every situation we've seen, this has been caused by programmer error.
Most often this indicates a race condition due to a forgotten 'return' or from commands in a previously run test bleeding into the current test.
For a much more thorough explanation including examples please review this error here:`,
docsUrl: 'https://on.cypress.io/command-queue-ended-early',
},
invalid_command: {
message: 'Could not find a command for: `{{name}}`.\n\nAvailable commands are: {{cmds}}.\n',
docsUrl: 'https://on.cypress.io/api',
},
invalid_new_command: {
message: '`Cypress.Commands.add()` is used to create new commands, but `{{name}}` is an existing Cypress command.\n\nPlease use `Cypress.Commands.overwrite()` if you would like to overwrite an existing command.\n',
docsUrl: 'https://on.cypress.io/custom-commands',
},
invalid_overwrite: {
message: 'Cannot overwite command for: `{{name}}`. An existing command does not exist by that name.',
docsUrl: 'https://on.cypress.io/api',
},
invoking_child_without_parent (obj) {
return stripIndent`\
Oops, it looks like you are trying to call a child command before running a parent command.
You wrote code that looks like this:
\`${cmd(obj.cmd, obj.args)}\`
A child command must be chained after a parent because it operates on a previous subject.
For example - if we were issuing the child command \`click\`...
cy
.get('button') // parent command must come first
.click() // then child command comes second`
},
no_cy: '`Cypress.cy` is `undefined`. You may be trying to query outside of a running test. Cannot call `Cypress.$()`',
no_runner: 'Cannot call `Cypress#run` without a runner instance.',
outside_test: {
message: stripIndent`\
Cypress cannot execute commands outside a running test.
This usually happens when you accidentally write commands outside an \`it(...)\` test.
If that is the case, just move these commands inside an \`it(...)\` test.
Check your test file for errors.`,
docsUrl: 'https://on.cypress.io/cannot-execute-commands-outside-test',
},
outside_test_with_cmd: {
message: stripIndent`\
Cannot call ${cmd('{{cmd}}')} outside a running test.
This usually happens when you accidentally write commands outside an \`it(...)\` test.
If that is the case, just move these commands inside an \`it(...)\` test.
Check your test file for errors.`,
docsUrl: 'https://on.cypress.io/cannot-execute-commands-outside-test',
},
private_custom_command_interface: 'You cannot use the undocumented private command interface: `{{method}}`',
retry_timed_out ({ ms }) {
return `Timed out retrying after ${ms}ms: `
},
cross_origin_command ({ commandOrigin, autOrigin }) {
return stripIndent`\
The command was expected to run against origin \`${commandOrigin }\` but the application is at origin \`${autOrigin}\`.
This commonly happens when you have either not navigated to the expected origin or have navigated away unexpectedly.`
},
},
mocha: {
async_timed_out: 'Timed out after `{{ms}}ms`. The `done()` callback was never invoked!',
invalid_interface: 'Invalid mocha interface `{{name}}`',
timed_out: 'Cypress command timeout of `{{ms}}ms` exceeded.',
overspecified: {
message: stripIndent`\
Cypress detected that you returned a promise in a test, but also invoked a done callback. Return a promise -or- invoke a done callback, not both.
Original mocha error:
{{error}}`,
docsUrl: 'https://on.cypress.io/returning-promise-and-invoking-done-callback',
},
manually_set_retries_test: stripIndent`\
Mocha \`this.retries()\` syntax is not supported.
To configure retries use the following syntax:
\`\`\`
it('{{title}}', { retries: {{numRetries}} }, () => {
...
})
\`\`\`
https://on.cypress.io/test-retries
`,
manually_set_retries_suite: stripIndent`\
Mocha \`this.retries()\` syntax is not supported.
To configure retries use the following syntax:
\`\`\`
describe('{{title}}', { retries: {{numRetries}} }, () => {
...
})
\`\`\`
https://on.cypress.io/test-retries
`,
hook_registered_late: stripIndent`\
Cypress detected you registered a(n) \`{{hookTitle}}\` hook while a test was running (possibly a hook nested inside another hook). All hooks must be registered before a test begins executing.
Move the \`{{hookTitle}}\` into a suite callback or the global scope.
`,
},
navigation: {
cross_origin ({ message, originPolicy, configFile }) {
return {
message: stripIndent`\
Cypress detected a cross origin error happened on page load:
> ${message}
Before the page load, you were bound to the origin policy:
> ${originPolicy}
A cross origin error happens when your application navigates to a new URL which does not match the origin policy above.
A new URL does not match the origin policy if the 'protocol', 'port' (if specified), and/or 'host' (unless of the same superdomain) are different.
Cypress does not allow you to navigate to a different origin URL within a single test.
You may need to restructure some of your test code to avoid this problem.
Alternatively you can also disable Chrome Web Security in Chromium-based browsers which will turn off this restriction by setting { chromeWebSecurity: false } in ${formatConfigFile(configFile)}.`,
docsUrl: 'https://on.cypress.io/cross-origin-violation',
}
},
timed_out ({ ms, configFile }) {
return stripIndent`\
Timed out after waiting \`${ms}ms\` for your remote page to load.
Your page did not fire its \`load\` event within \`${ms}ms\`.
You can try increasing the \`pageLoadTimeout\` value in ${formatConfigFile(configFile)} to wait longer.
Browsers will not fire the \`load\` event until all stylesheets and scripts are done downloading.
When this \`load\` event occurs, Cypress will continue running commands.`
},
reached_redirection_limit ({ href, limit }) {
return stripIndent`\
The application redirected to \`${href}\` more than ${limit} times. Please check if it's an intended behavior.
If so, increase \`redirectionLimit\` value in configuration.`
},
cross_origin_load_timed_out ({ ms, configFile, crossOriginUrl, originPolicies }) {
return {
message: stripIndent`\
Timed out after waiting \`${ms}ms\` for your remote page to load on origin(s):
- ${originPolicies.map((originPolicy) => `\`${originPolicy}\``).join('\n -')}