|
| 1 | +/** |
| 2 | + * File that tests whether the TypeScript typings for @types/jest work as expected. |
| 3 | + */ |
| 4 | + |
| 5 | +/* eslint-disable @typescript-eslint/no-unsafe-call */ |
| 6 | +/* eslint-disable @typescript-eslint/no-floating-promises */ |
| 7 | +/* eslint-disable @typescript-eslint/no-unsafe-argument */ |
| 8 | + |
| 9 | +import {expect} from '@jest/globals' |
| 10 | +import '../../jest-globals' |
| 11 | + |
| 12 | +const element: HTMLElement = document.body |
| 13 | + |
| 14 | +expect(element).toBeInTheDOM() |
| 15 | +expect(element).toBeInTheDOM(document.body) |
| 16 | +expect(element).toBeInTheDocument() |
| 17 | +expect(element).toBeVisible() |
| 18 | +expect(element).toBeEmpty() |
| 19 | +expect(element).toBeDisabled() |
| 20 | +expect(element).toBeEnabled() |
| 21 | +expect(element).toBeInvalid() |
| 22 | +expect(element).toBeRequired() |
| 23 | +expect(element).toBeValid() |
| 24 | +expect(element).toContainElement(document.body) |
| 25 | +expect(element).toContainElement(null) |
| 26 | +expect(element).toContainHTML('body') |
| 27 | +expect(element).toHaveAttribute('attr') |
| 28 | +expect(element).toHaveAttribute('attr', true) |
| 29 | +expect(element).toHaveAttribute('attr', 'yes') |
| 30 | +expect(element).toHaveClass() |
| 31 | +expect(element).toHaveClass('cls1') |
| 32 | +expect(element).toHaveClass('cls1', 'cls2', 'cls3', 'cls4') |
| 33 | +expect(element).toHaveClass('cls1', {exact: true}) |
| 34 | +expect(element).toHaveDisplayValue('str') |
| 35 | +expect(element).toHaveDisplayValue(['str1', 'str2']) |
| 36 | +expect(element).toHaveDisplayValue(/str/) |
| 37 | +expect(element).toHaveDisplayValue([/str1/, 'str2']) |
| 38 | +expect(element).toHaveFocus() |
| 39 | +expect(element).toHaveFormValues({foo: 'bar', baz: 1}) |
| 40 | +expect(element).toHaveStyle('display: block') |
| 41 | +expect(element).toHaveStyle({display: 'block', width: 100}) |
| 42 | +expect(element).toHaveTextContent('Text') |
| 43 | +expect(element).toHaveTextContent(/Text/) |
| 44 | +expect(element).toHaveTextContent('Text', {normalizeWhitespace: true}) |
| 45 | +expect(element).toHaveTextContent(/Text/, {normalizeWhitespace: true}) |
| 46 | +expect(element).toHaveValue() |
| 47 | +expect(element).toHaveValue('str') |
| 48 | +expect(element).toHaveValue(['str1', 'str2']) |
| 49 | +expect(element).toHaveValue(1) |
| 50 | +expect(element).toHaveValue(null) |
| 51 | +expect(element).toBeChecked() |
| 52 | +expect(element).toHaveDescription('some description') |
| 53 | +expect(element).toHaveDescription(/some description/) |
| 54 | +expect(element).toHaveDescription(expect.stringContaining('partial')) |
| 55 | +expect(element).toHaveDescription() |
| 56 | +expect(element).toHaveAccessibleDescription('some description') |
| 57 | +expect(element).toHaveAccessibleDescription(/some description/) |
| 58 | +expect(element).toHaveAccessibleDescription(expect.stringContaining('partial')) |
| 59 | +expect(element).toHaveAccessibleDescription() |
| 60 | +expect(element).toHaveAccessibleName('a label') |
| 61 | +expect(element).toHaveAccessibleName(/a label/) |
| 62 | +expect(element).toHaveAccessibleName(expect.stringContaining('partial label')) |
| 63 | +expect(element).toHaveAccessibleName() |
| 64 | +expect(element).toHaveErrorMessage( |
| 65 | + 'Invalid time: the time must be between 9:00 AM and 5:00 PM', |
| 66 | +) |
| 67 | +expect(element).toHaveErrorMessage(/invalid time/i) |
| 68 | +expect(element).toHaveErrorMessage(expect.stringContaining('Invalid time')) |
| 69 | + |
| 70 | +expect(element).not.toBeInTheDOM() |
| 71 | +expect(element).not.toBeInTheDOM(document.body) |
| 72 | +expect(element).not.toBeInTheDocument() |
| 73 | +expect(element).not.toBeVisible() |
| 74 | +expect(element).not.toBeEmpty() |
| 75 | +expect(element).not.toBeEmptyDOMElement() |
| 76 | +expect(element).not.toBeDisabled() |
| 77 | +expect(element).not.toBeEnabled() |
| 78 | +expect(element).not.toBeInvalid() |
| 79 | +expect(element).not.toBeRequired() |
| 80 | +expect(element).not.toBeValid() |
| 81 | +expect(element).not.toContainElement(document.body) |
| 82 | +expect(element).not.toContainElement(null) |
| 83 | +expect(element).not.toContainHTML('body') |
| 84 | +expect(element).not.toHaveAttribute('attr') |
| 85 | +expect(element).not.toHaveAttribute('attr', true) |
| 86 | +expect(element).not.toHaveAttribute('attr', 'yes') |
| 87 | +expect(element).not.toHaveClass() |
| 88 | +expect(element).not.toHaveClass('cls1') |
| 89 | +expect(element).not.toHaveClass('cls1', 'cls2', 'cls3', 'cls4') |
| 90 | +expect(element).not.toHaveClass('cls1', {exact: true}) |
| 91 | +expect(element).not.toHaveDisplayValue('str') |
| 92 | +expect(element).not.toHaveDisplayValue(['str1', 'str2']) |
| 93 | +expect(element).not.toHaveDisplayValue(/str/) |
| 94 | +expect(element).not.toHaveDisplayValue([/str1/, 'str2']) |
| 95 | +expect(element).not.toHaveFocus() |
| 96 | +expect(element).not.toHaveFormValues({foo: 'bar', baz: 1}) |
| 97 | +expect(element).not.toHaveStyle('display: block') |
| 98 | +expect(element).not.toHaveTextContent('Text') |
| 99 | +expect(element).not.toHaveTextContent(/Text/) |
| 100 | +expect(element).not.toHaveTextContent('Text', {normalizeWhitespace: true}) |
| 101 | +expect(element).not.toHaveTextContent(/Text/, {normalizeWhitespace: true}) |
| 102 | +expect(element).not.toHaveValue() |
| 103 | +expect(element).not.toHaveValue('str') |
| 104 | +expect(element).not.toHaveValue(['str1', 'str2']) |
| 105 | +expect(element).not.toHaveValue(1) |
| 106 | +expect(element).not.toBeChecked() |
| 107 | +expect(element).not.toHaveDescription('some description') |
| 108 | +expect(element).not.toHaveDescription() |
| 109 | +expect(element).not.toHaveAccessibleDescription('some description') |
| 110 | +expect(element).not.toHaveAccessibleDescription() |
| 111 | +expect(element).not.toHaveAccessibleName('a label') |
| 112 | +expect(element).not.toHaveAccessibleName() |
| 113 | +expect(element).not.toBePartiallyChecked() |
| 114 | +expect(element).not.toHaveErrorMessage() |
| 115 | +expect(element).not.toHaveErrorMessage('Pikachu!') |
| 116 | + |
| 117 | +// @ts-expect-error The types accidentally allowed any property by falling back to "any" |
| 118 | +expect(element).nonExistentProperty() |
0 commit comments