@voidzero-dev/vite-plus-test 0.0.0-0bfcc90f.20260209-0731
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/LICENSE.md +691 -0
- package/browser/context.d.ts +4 -0
- package/browser/context.js +20 -0
- package/config.d.ts +3 -0
- package/coverage.d.ts +1 -0
- package/dist/@vitest/browser/client/.vite/manifest.json +24 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +57 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +1 -0
- package/dist/@vitest/browser/client/__vitest__/bg.png +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.svg +5 -0
- package/dist/@vitest/browser/client/__vitest__/index.html +32 -0
- package/dist/@vitest/browser/client/__vitest_browser__/orchestrator-S_3e_uzt.js +345 -0
- package/dist/@vitest/browser/client/__vitest_browser__/tester-k74mgIRa.js +2171 -0
- package/dist/@vitest/browser/client/__vitest_browser__/utils-uxqdqUz8.js +223 -0
- package/dist/@vitest/browser/client/error-catcher.js +82 -0
- package/dist/@vitest/browser/client/esm-client-injector.js +67 -0
- package/dist/@vitest/browser/client/favicon.svg +5 -0
- package/dist/@vitest/browser/client/orchestrator.html +35 -0
- package/dist/@vitest/browser/client/tester/tester.html +13 -0
- package/dist/@vitest/browser/client.js +456 -0
- package/dist/@vitest/browser/context.d.ts +792 -0
- package/dist/@vitest/browser/context.js +541 -0
- package/dist/@vitest/browser/expect-element.js +32 -0
- package/dist/@vitest/browser/index-D6m36C6U.js +11 -0
- package/dist/@vitest/browser/index.d.ts +73 -0
- package/dist/@vitest/browser/index.js +3513 -0
- package/dist/@vitest/browser/jest-dom.d.ts +724 -0
- package/dist/@vitest/browser/locators.d.ts +354 -0
- package/dist/@vitest/browser/locators.js +1 -0
- package/dist/@vitest/browser/matchers.d.ts +29 -0
- package/dist/@vitest/browser/shared/screenshotMatcher/types.d.ts +22 -0
- package/dist/@vitest/browser/state.js +280 -0
- package/dist/@vitest/browser/types.d.ts +69 -0
- package/dist/@vitest/browser-playwright/context.d.ts +1 -0
- package/dist/@vitest/browser-playwright/index.d.ts +106 -0
- package/dist/@vitest/browser-playwright/index.js +1111 -0
- package/dist/@vitest/browser-playwright/locators.js +114 -0
- package/dist/@vitest/browser-preview/context.d.ts +1 -0
- package/dist/@vitest/browser-preview/index.d.ts +19 -0
- package/dist/@vitest/browser-preview/index.js +148 -0
- package/dist/@vitest/browser-preview/locators.js +79 -0
- package/dist/@vitest/browser-webdriverio/context.d.ts +1 -0
- package/dist/@vitest/browser-webdriverio/index.d.ts +63 -0
- package/dist/@vitest/browser-webdriverio/index.js +600 -0
- package/dist/@vitest/browser-webdriverio/locators.js +163 -0
- package/dist/@vitest/expect/index.d.ts +807 -0
- package/dist/@vitest/expect/index.js +1875 -0
- package/dist/@vitest/mocker/auto-register.d.ts +2 -0
- package/dist/@vitest/mocker/auto-register.js +9 -0
- package/dist/@vitest/mocker/automock.d.ts +12 -0
- package/dist/@vitest/mocker/automock.js +1 -0
- package/dist/@vitest/mocker/browser.d.ts +53 -0
- package/dist/@vitest/mocker/browser.js +91 -0
- package/dist/@vitest/mocker/chunk-automock.js +354 -0
- package/dist/@vitest/mocker/chunk-interceptor-native.js +15 -0
- package/dist/@vitest/mocker/chunk-mocker.js +521 -0
- package/dist/@vitest/mocker/chunk-pathe.M-eThtNZ.js +174 -0
- package/dist/@vitest/mocker/chunk-registry.js +185 -0
- package/dist/@vitest/mocker/chunk-utils.js +16 -0
- package/dist/@vitest/mocker/index.d-C-sLYZi-.d.ts +25 -0
- package/dist/@vitest/mocker/index.d.ts +2 -0
- package/dist/@vitest/mocker/index.js +185 -0
- package/dist/@vitest/mocker/mocker.d-TnKRhz7N.d.ts +81 -0
- package/dist/@vitest/mocker/node.d.ts +800 -0
- package/dist/@vitest/mocker/node.js +966 -0
- package/dist/@vitest/mocker/redirect.d.ts +3 -0
- package/dist/@vitest/mocker/redirect.js +79 -0
- package/dist/@vitest/mocker/register.d.ts +9 -0
- package/dist/@vitest/mocker/register.js +41 -0
- package/dist/@vitest/mocker/types.d-B8CCKmHt.d.ts +107 -0
- package/dist/@vitest/pretty-format/index.d.ts +124 -0
- package/dist/@vitest/pretty-format/index.js +1022 -0
- package/dist/@vitest/runner/chunk-tasks.js +340 -0
- package/dist/@vitest/runner/index.d.ts +180 -0
- package/dist/@vitest/runner/index.js +2114 -0
- package/dist/@vitest/runner/tasks.d-C7UxawJ9.d.ts +834 -0
- package/dist/@vitest/runner/types.d.ts +183 -0
- package/dist/@vitest/runner/types.js +1 -0
- package/dist/@vitest/runner/utils.d.ts +45 -0
- package/dist/@vitest/runner/utils.js +5 -0
- package/dist/@vitest/snapshot/environment.d-DHdQ1Csl.d.ts +22 -0
- package/dist/@vitest/snapshot/environment.d.ts +16 -0
- package/dist/@vitest/snapshot/environment.js +40 -0
- package/dist/@vitest/snapshot/index.d.ts +130 -0
- package/dist/@vitest/snapshot/index.js +1437 -0
- package/dist/@vitest/snapshot/manager.d.ts +18 -0
- package/dist/@vitest/snapshot/manager.js +73 -0
- package/dist/@vitest/snapshot/rawSnapshot.d-lFsMJFUd.d.ts +61 -0
- package/dist/@vitest/spy/index.d.ts +384 -0
- package/dist/@vitest/spy/index.js +433 -0
- package/dist/@vitest/utils/chunk-_commonjsHelpers.js +5 -0
- package/dist/@vitest/utils/chunk-pathe.M-eThtNZ.js +156 -0
- package/dist/@vitest/utils/constants.d.ts +21 -0
- package/dist/@vitest/utils/constants.js +49 -0
- package/dist/@vitest/utils/diff.d.ts +93 -0
- package/dist/@vitest/utils/diff.js +2199 -0
- package/dist/@vitest/utils/display.d.ts +29 -0
- package/dist/@vitest/utils/display.js +742 -0
- package/dist/@vitest/utils/error.d.ts +7 -0
- package/dist/@vitest/utils/error.js +42 -0
- package/dist/@vitest/utils/helpers.d.ts +73 -0
- package/dist/@vitest/utils/helpers.js +295 -0
- package/dist/@vitest/utils/highlight.d.ts +9 -0
- package/dist/@vitest/utils/highlight.js +538 -0
- package/dist/@vitest/utils/index.d.ts +5 -0
- package/dist/@vitest/utils/index.js +1 -0
- package/dist/@vitest/utils/offset.d.ts +5 -0
- package/dist/@vitest/utils/offset.js +32 -0
- package/dist/@vitest/utils/resolver.d.ts +7 -0
- package/dist/@vitest/utils/resolver.js +71 -0
- package/dist/@vitest/utils/serialize.d.ts +3 -0
- package/dist/@vitest/utils/serialize.js +118 -0
- package/dist/@vitest/utils/source-map.d.ts +55 -0
- package/dist/@vitest/utils/source-map.js +478 -0
- package/dist/@vitest/utils/timers.d.ts +33 -0
- package/dist/@vitest/utils/timers.js +49 -0
- package/dist/@vitest/utils/types.d-BCElaP-c.d.ts +53 -0
- package/dist/@vitest/utils/types.d.ts +34 -0
- package/dist/@vitest/utils/types.js +1 -0
- package/dist/browser-compat.js +3 -0
- package/dist/browser.d.ts +46 -0
- package/dist/browser.js +20 -0
- package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +6 -0
- package/dist/chunks/base.CJ0Y4ePK.js +165 -0
- package/dist/chunks/benchmark.B3N2zMcH.js +40 -0
- package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +24 -0
- package/dist/chunks/browser.d.ChKACdzH.d.ts +59 -0
- package/dist/chunks/cac.DVeoLl0M.js +1409 -0
- package/dist/chunks/cli-api.B7PN_QUv.js +13672 -0
- package/dist/chunks/config.d.Cy95HiCx.d.ts +210 -0
- package/dist/chunks/console.Cf-YriPC.js +146 -0
- package/dist/chunks/constants.D_Q9UYh-.js +36 -0
- package/dist/chunks/coverage.AVPTjMgw.js +3292 -0
- package/dist/chunks/coverage.D_JHT54q.js +25 -0
- package/dist/chunks/coverage.d.BZtK59WP.d.ts +37 -0
- package/dist/chunks/creator.DAmOKTvJ.js +673 -0
- package/dist/chunks/date.Bq6ZW5rf.js +73 -0
- package/dist/chunks/defaults.BOqNVLsY.js +74 -0
- package/dist/chunks/env.D4Lgay0q.js +8 -0
- package/dist/chunks/environment.d.CrsxCzP1.d.ts +29 -0
- package/dist/chunks/evaluatedModules.Dg1zASAC.js +17 -0
- package/dist/chunks/evaluatedModules.d.BxJ5omdx.d.ts +7 -0
- package/dist/chunks/git.Bm2pzPAa.js +71 -0
- package/dist/chunks/global.d.B15mdLcR.d.ts +99 -0
- package/dist/chunks/globals.DOayXfHP.js +30 -0
- package/dist/chunks/index.6Qv1eEA6.js +109 -0
- package/dist/chunks/index.C5r1PdPD.js +231 -0
- package/dist/chunks/index.Chj8NDwU.js +206 -0
- package/dist/chunks/index.CyBMJtT7.js +727 -0
- package/dist/chunks/index.D3XRDfWc.js +213 -0
- package/dist/chunks/index.D4KonVSU.js +6343 -0
- package/dist/chunks/index.M8mOzt4Y.js +3839 -0
- package/dist/chunks/index.Z5E_ObnR.js +37 -0
- package/dist/chunks/init-forks._y3TW739.js +41 -0
- package/dist/chunks/init-threads.DBO2kn-p.js +18 -0
- package/dist/chunks/init.B6MLFIaN.js +334 -0
- package/dist/chunks/inspector.CvyFGlXm.js +53 -0
- package/dist/chunks/modules.BJuCwlRJ.js +36 -0
- package/dist/chunks/node.Ce0vMQM7.js +14 -0
- package/dist/chunks/plugin.d.CtqpEehP.d.ts +38 -0
- package/dist/chunks/reporters.d.CWXNI2jG.d.ts +3271 -0
- package/dist/chunks/rpc.BoxB0q7B.js +76 -0
- package/dist/chunks/rpc.d.RH3apGEf.d.ts +64 -0
- package/dist/chunks/setup-common.Cm-kSBVi.js +60 -0
- package/dist/chunks/startModuleRunner.DEj0jb3e.js +861 -0
- package/dist/chunks/suite.d.BJWk38HB.d.ts +10 -0
- package/dist/chunks/test.B8ej_ZHS.js +254 -0
- package/dist/chunks/traces.CCmnQaNT.js +217 -0
- package/dist/chunks/traces.d.402V_yFI.d.ts +18 -0
- package/dist/chunks/utils.DvEY5TfP.js +52 -0
- package/dist/chunks/vi.2VT5v0um.js +3919 -0
- package/dist/chunks/vm.D3epNOPZ.js +744 -0
- package/dist/chunks/worker.d.Dyxm8DEL.d.ts +255 -0
- package/dist/cli.js +28 -0
- package/dist/client/.vite/manifest.json +24 -0
- package/dist/client/__vitest__/assets/index-BUCFJtth.js +57 -0
- package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +1 -0
- package/dist/client/__vitest__/bg.png +0 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/favicon.svg +5 -0
- package/dist/client/__vitest__/index.html +32 -0
- package/dist/client/__vitest_browser__/orchestrator-S_3e_uzt.js +345 -0
- package/dist/client/__vitest_browser__/tester-k74mgIRa.js +2171 -0
- package/dist/client/__vitest_browser__/utils-uxqdqUz8.js +223 -0
- package/dist/client/error-catcher.js +82 -0
- package/dist/client/esm-client-injector.js +67 -0
- package/dist/client/favicon.svg +5 -0
- package/dist/client/orchestrator.html +35 -0
- package/dist/client/tester/tester.html +13 -0
- package/dist/client.js +456 -0
- package/dist/config.cjs +94 -0
- package/dist/config.d.ts +104 -0
- package/dist/config.js +15 -0
- package/dist/context.js +541 -0
- package/dist/coverage.d.ts +118 -0
- package/dist/coverage.js +23 -0
- package/dist/dummy.js +2 -0
- package/dist/environments.d.ts +22 -0
- package/dist/environments.js +3 -0
- package/dist/expect-element.js +27 -0
- package/dist/index-D6m36C6U.js +6 -0
- package/dist/index-node.js +7 -0
- package/dist/index.d.ts +510 -0
- package/dist/index.js +19 -0
- package/dist/locators.d.ts +354 -0
- package/dist/locators.js +1 -0
- package/dist/mocker.d.ts +1 -0
- package/dist/mocker.js +1 -0
- package/dist/module-evaluator.d.ts +124 -0
- package/dist/module-evaluator.js +343 -0
- package/dist/module-runner-stub.js +44 -0
- package/dist/module-runner.js +17 -0
- package/dist/node.d.ts +251 -0
- package/dist/node.js +98 -0
- package/dist/path.js +7 -0
- package/dist/plugins/browser-client.mjs +2 -0
- package/dist/plugins/browser-context.mjs +2 -0
- package/dist/plugins/browser-locators.mjs +2 -0
- package/dist/plugins/browser-playwright.mjs +2 -0
- package/dist/plugins/browser-preview.mjs +2 -0
- package/dist/plugins/browser-webdriverio.mjs +2 -0
- package/dist/plugins/browser.mjs +2 -0
- package/dist/plugins/expect.mjs +2 -0
- package/dist/plugins/mocker-automock.mjs +2 -0
- package/dist/plugins/mocker-browser.mjs +2 -0
- package/dist/plugins/mocker-node.mjs +2 -0
- package/dist/plugins/mocker-redirect.mjs +2 -0
- package/dist/plugins/mocker-register.mjs +2 -0
- package/dist/plugins/mocker.mjs +2 -0
- package/dist/plugins/pretty-format.mjs +2 -0
- package/dist/plugins/runner-types.mjs +2 -0
- package/dist/plugins/runner-utils.mjs +2 -0
- package/dist/plugins/runner.mjs +2 -0
- package/dist/plugins/snapshot-environment.mjs +2 -0
- package/dist/plugins/snapshot-manager.mjs +2 -0
- package/dist/plugins/snapshot.mjs +2 -0
- package/dist/plugins/spy.mjs +2 -0
- package/dist/plugins/utils-constants.mjs +2 -0
- package/dist/plugins/utils-diff.mjs +2 -0
- package/dist/plugins/utils-display.mjs +2 -0
- package/dist/plugins/utils-error.mjs +2 -0
- package/dist/plugins/utils-helpers.mjs +2 -0
- package/dist/plugins/utils-highlight.mjs +2 -0
- package/dist/plugins/utils-offset.mjs +2 -0
- package/dist/plugins/utils-resolver.mjs +2 -0
- package/dist/plugins/utils-serialize.mjs +2 -0
- package/dist/plugins/utils-source-map.mjs +2 -0
- package/dist/plugins/utils-timers.mjs +2 -0
- package/dist/plugins/utils.mjs +2 -0
- package/dist/reporters.d.ts +27 -0
- package/dist/reporters.js +24 -0
- package/dist/runners.d.ts +50 -0
- package/dist/runners.js +19 -0
- package/dist/shared/screenshotMatcher/types.d.ts +22 -0
- package/dist/snapshot.d.ts +9 -0
- package/dist/snapshot.js +4 -0
- package/dist/spy.js +1 -0
- package/dist/state.js +280 -0
- package/dist/suite.d.ts +5 -0
- package/dist/suite.js +6 -0
- package/dist/types.d.ts +69 -0
- package/dist/vendor/chai.d.mts +1 -0
- package/dist/vendor/chai.mjs +3577 -0
- package/dist/vendor/es-module-lexer.d.mts +193 -0
- package/dist/vendor/es-module-lexer.mjs +79 -0
- package/dist/vendor/estree-walker.d.mts +583 -0
- package/dist/vendor/estree-walker.mjs +339 -0
- package/dist/vendor/expect-type.d.mts +1574 -0
- package/dist/vendor/expect-type.mjs +214 -0
- package/dist/vendor/magic-string.d.mts +261 -0
- package/dist/vendor/magic-string.mjs +1700 -0
- package/dist/vendor/obug.d.mts +56 -0
- package/dist/vendor/obug.mjs +276 -0
- package/dist/vendor/pathe.d.mts +46 -0
- package/dist/vendor/pathe.mjs +496 -0
- package/dist/vendor/picomatch.d.mts +1 -0
- package/dist/vendor/picomatch.mjs +1855 -0
- package/dist/vendor/shared-3g9mwCWP.mjs +31 -0
- package/dist/vendor/std-env.d.mts +88 -0
- package/dist/vendor/std-env.mjs +159 -0
- package/dist/vendor/tinybench.d.mts +317 -0
- package/dist/vendor/tinybench.mjs +504 -0
- package/dist/vendor/tinyexec.d.mts +72 -0
- package/dist/vendor/tinyexec.mjs +637 -0
- package/dist/vendor/tinyglobby.d.mts +157 -0
- package/dist/vendor/tinyglobby.mjs +832 -0
- package/dist/vendor/tinyrainbow.d.mts +60 -0
- package/dist/vendor/tinyrainbow.mjs +93 -0
- package/dist/vendor/vitest_browser.mjs +2 -0
- package/dist/vendor/vitest_internal_browser.mjs +2 -0
- package/dist/vendor/vitest_runner.mjs +2 -0
- package/dist/vendor/vitest_runners.mjs +2 -0
- package/dist/worker.d.ts +32 -0
- package/dist/worker.js +48 -0
- package/dist/workers/forks.js +54 -0
- package/dist/workers/runVmTests.js +95 -0
- package/dist/workers/threads.js +55 -0
- package/dist/workers/vmForks.js +36 -0
- package/dist/workers/vmThreads.js +37 -0
- package/environments.d.ts +1 -0
- package/globals.d.ts +20 -0
- package/import-meta.d.ts +5 -0
- package/importMeta.d.ts +4 -0
- package/index.cjs +5 -0
- package/index.d.cts +1 -0
- package/jsdom.d.ts +6 -0
- package/mocker.d.ts +1 -0
- package/node.d.ts +1 -0
- package/optional-types.d.ts +7 -0
- package/package.json +335 -0
- package/reporters.d.ts +1 -0
- package/runners.d.ts +1 -0
- package/snapshot.d.ts +1 -0
- package/suite.d.ts +1 -0
- package/suppress-warnings.cjs +21 -0
- package/vitest.mjs +2 -0
- package/worker.d.ts +1 -0
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
// Disable automatic exports.
|
|
2
|
+
|
|
3
|
+
import { ARIARole } from './aria-role.ts'
|
|
4
|
+
import { Locator, ScreenshotComparatorRegistry, ScreenshotMatcherOptions } from './context.js'
|
|
5
|
+
|
|
6
|
+
export interface TestingLibraryMatchers<E, R> {
|
|
7
|
+
/**
|
|
8
|
+
* @description
|
|
9
|
+
* Assert whether an element is present in the document or not.
|
|
10
|
+
* @example
|
|
11
|
+
* <svg data-testid="svg-element"></svg>
|
|
12
|
+
*
|
|
13
|
+
* await expect.element(page.getByTestId('svg-element')).toBeInTheDocument()
|
|
14
|
+
* await expect.element(page.getByTestId('does-not-exist')).not.toBeInTheDocument()
|
|
15
|
+
* @see https://vitest.dev/api/browser/assertions#tobeinthedocument
|
|
16
|
+
*/
|
|
17
|
+
toBeInTheDocument(): R
|
|
18
|
+
/**
|
|
19
|
+
* @description
|
|
20
|
+
* Assert whether an element is within the viewport or not.
|
|
21
|
+
*
|
|
22
|
+
* An element is considered to be in the viewport if any part of it intersects with the current viewport bounds.
|
|
23
|
+
* This matcher calculates the intersection ratio between the element and the viewport, similar to the
|
|
24
|
+
* IntersectionObserver API.
|
|
25
|
+
*
|
|
26
|
+
* The element must be in the document and have visible dimensions. Elements with display: none or
|
|
27
|
+
* visibility: hidden are considered not in viewport.
|
|
28
|
+
* @example
|
|
29
|
+
* <div
|
|
30
|
+
* data-testid="visible-element"
|
|
31
|
+
* style="position: absolute; top: 10px; left: 10px; width: 50px; height: 50px;"
|
|
32
|
+
* >
|
|
33
|
+
* Visible Element
|
|
34
|
+
* </div>
|
|
35
|
+
*
|
|
36
|
+
* <div
|
|
37
|
+
* data-testid="hidden-element"
|
|
38
|
+
* style="position: fixed; top: -100px; left: 10px; width: 50px; height: 50px;"
|
|
39
|
+
* >
|
|
40
|
+
* Hidden Element
|
|
41
|
+
* </div>
|
|
42
|
+
*
|
|
43
|
+
* <div
|
|
44
|
+
* data-testid="large-element"
|
|
45
|
+
* style="height: 400vh;"
|
|
46
|
+
* >
|
|
47
|
+
* Large Element
|
|
48
|
+
* </div>
|
|
49
|
+
*
|
|
50
|
+
* // Check if any part of element is in viewport
|
|
51
|
+
* await expect.element(page.getByTestId('visible-element')).toBeInViewport()
|
|
52
|
+
*
|
|
53
|
+
* // Check if element is outside viewport
|
|
54
|
+
* await expect.element(page.getByTestId('hidden-element')).not.toBeInViewport()
|
|
55
|
+
*
|
|
56
|
+
* // Check if at least 50% of element is visible
|
|
57
|
+
* await expect.element(page.getByTestId('large-element')).toBeInViewport({ ratio: 0.5 })
|
|
58
|
+
*
|
|
59
|
+
* // Check if element is completely visible
|
|
60
|
+
* await expect.element(page.getByTestId('visible-element')).toBeInViewport({ ratio: 1 })
|
|
61
|
+
* @see https://vitest.dev/api/browser/assertions#tobeinviewport
|
|
62
|
+
*/
|
|
63
|
+
toBeInViewport(options?: { ratio?: number }): R
|
|
64
|
+
/**
|
|
65
|
+
* @description
|
|
66
|
+
* This allows you to check if an element is currently visible to the user.
|
|
67
|
+
*
|
|
68
|
+
* An element is visible if **all** the following conditions are met:
|
|
69
|
+
* * it does not have its css property display set to none
|
|
70
|
+
* * it does not have its css property visibility set to either hidden or collapse
|
|
71
|
+
* * it does not have its css property opacity set to 0
|
|
72
|
+
* * its parent element is also visible (and so on up to the top of the DOM tree)
|
|
73
|
+
* * it does not have the hidden attribute
|
|
74
|
+
* * if `<details />` it has the open attribute
|
|
75
|
+
* @example
|
|
76
|
+
* <div
|
|
77
|
+
* data-testid="zero-opacity"
|
|
78
|
+
* style="opacity: 0"
|
|
79
|
+
* >
|
|
80
|
+
* Zero Opacity
|
|
81
|
+
* </div>
|
|
82
|
+
*
|
|
83
|
+
* <div data-testid="visible">Visible Example</div>
|
|
84
|
+
*
|
|
85
|
+
* await expect.element(page.getByTestId('zero-opacity')).not.toBeVisible()
|
|
86
|
+
* await expect.element(page.getByTestId('visible')).toBeVisible()
|
|
87
|
+
* @see https://vitest.dev/api/browser/assertions#tobevisible
|
|
88
|
+
*/
|
|
89
|
+
toBeVisible(): R
|
|
90
|
+
/**
|
|
91
|
+
* @description
|
|
92
|
+
* Assert whether an element has content or not.
|
|
93
|
+
* @example
|
|
94
|
+
* <span data-testid="not-empty">
|
|
95
|
+
* <span data-testid="empty"></span>
|
|
96
|
+
* </span>
|
|
97
|
+
*
|
|
98
|
+
* await expect.element(page.getByTestId('empty')).toBeEmptyDOMElement()
|
|
99
|
+
* await expect.element(page.getByTestId('not-empty')).not.toBeEmptyDOMElement()
|
|
100
|
+
* @see https://vitest.dev/api/browser/assertions#tobeemptydomelement
|
|
101
|
+
*/
|
|
102
|
+
toBeEmptyDOMElement(): R
|
|
103
|
+
/**
|
|
104
|
+
* @description
|
|
105
|
+
* Allows you to check whether an element is disabled from the user's perspective.
|
|
106
|
+
*
|
|
107
|
+
* Matches if the element is a form control and the `disabled` attribute is specified on this element or the
|
|
108
|
+
* element is a descendant of a form element with a `disabled` attribute.
|
|
109
|
+
* @example
|
|
110
|
+
* <button
|
|
111
|
+
* data-testid="button"
|
|
112
|
+
* type="submit"
|
|
113
|
+
* disabled
|
|
114
|
+
* >
|
|
115
|
+
* submit
|
|
116
|
+
* </button>
|
|
117
|
+
*
|
|
118
|
+
* await expect.element(page.getByTestId('button')).toBeDisabled()
|
|
119
|
+
* @see https://vitest.dev/api/browser/assertions#tobedisabled
|
|
120
|
+
*/
|
|
121
|
+
toBeDisabled(): R
|
|
122
|
+
/**
|
|
123
|
+
* @description
|
|
124
|
+
* Allows you to check whether an element is not disabled from the user's perspective.
|
|
125
|
+
*
|
|
126
|
+
* Works like `not.toBeDisabled()`.
|
|
127
|
+
*
|
|
128
|
+
* Use this matcher to avoid double negation in your tests.
|
|
129
|
+
* @example
|
|
130
|
+
* <button
|
|
131
|
+
* data-testid="button"
|
|
132
|
+
* type="submit"
|
|
133
|
+
* >
|
|
134
|
+
* submit
|
|
135
|
+
* </button>
|
|
136
|
+
*
|
|
137
|
+
* await expect.element(page.getByTestId('button')).toBeEnabled()
|
|
138
|
+
* @see https://vitest.dev/api/browser/assertions#tobeenabled
|
|
139
|
+
*/
|
|
140
|
+
toBeEnabled(): R
|
|
141
|
+
/**
|
|
142
|
+
* @description
|
|
143
|
+
* Check if a form element, or the entire `form`, is currently invalid.
|
|
144
|
+
*
|
|
145
|
+
* An `input`, `select`, `textarea`, or `form` element is invalid if it has an `aria-invalid` attribute with no
|
|
146
|
+
* value or a value of "true", or if the result of `checkValidity()` is false.
|
|
147
|
+
* @example
|
|
148
|
+
* <input data-testid="no-aria-invalid" />
|
|
149
|
+
*
|
|
150
|
+
* <form data-testid="invalid-form">
|
|
151
|
+
* <input required />
|
|
152
|
+
* </form>
|
|
153
|
+
*
|
|
154
|
+
* await expect(page.getByTestId('no-aria-invalid')).not.toBeInvalid()
|
|
155
|
+
* await expect(page.getByTestId('invalid-form')).toBeInvalid()
|
|
156
|
+
* @see https://vitest.dev/api/browser/assertions#tobeinvalid
|
|
157
|
+
*/
|
|
158
|
+
toBeInvalid(): R
|
|
159
|
+
/**
|
|
160
|
+
* @description
|
|
161
|
+
* This allows you to check if a form element is currently required.
|
|
162
|
+
*
|
|
163
|
+
* An element is required if it is having a `required` or `aria-required="true"` attribute.
|
|
164
|
+
* @example
|
|
165
|
+
* <input data-testid="required-input" required />
|
|
166
|
+
* <div
|
|
167
|
+
* data-testid="supported-role"
|
|
168
|
+
* role="tree"
|
|
169
|
+
* required />
|
|
170
|
+
*
|
|
171
|
+
* await expect.element(page.getByTestId('required-input')).toBeRequired()
|
|
172
|
+
* await expect.element(page.getByTestId('supported-role')).not.toBeRequired()
|
|
173
|
+
* @see https://vitest.dev/api/browser/assertions#toberequired
|
|
174
|
+
*/
|
|
175
|
+
toBeRequired(): R
|
|
176
|
+
/**
|
|
177
|
+
* @description
|
|
178
|
+
* Allows you to check if a form element is currently required.
|
|
179
|
+
*
|
|
180
|
+
* An `input`, `select`, `textarea`, or `form` element is invalid if it has an `aria-invalid` attribute with no
|
|
181
|
+
* value or a value of "false", or if the result of `checkValidity()` is true.
|
|
182
|
+
* @example
|
|
183
|
+
* <input data-testid="aria-invalid" aria-invalid />
|
|
184
|
+
*
|
|
185
|
+
* <form data-testid="valid-form">
|
|
186
|
+
* <input />
|
|
187
|
+
* </form>
|
|
188
|
+
*
|
|
189
|
+
* await expect.element(page.getByTestId('no-aria-invalid')).not.toBeValid()
|
|
190
|
+
* await expect.element(page.getByTestId('invalid-form')).toBeInvalid()
|
|
191
|
+
* @see https://vitest.dev/api/browser/assertions#tobevalid
|
|
192
|
+
*/
|
|
193
|
+
toBeValid(): R
|
|
194
|
+
/**
|
|
195
|
+
* @description
|
|
196
|
+
* Allows you to assert whether an element contains another element as a descendant or not.
|
|
197
|
+
* @example
|
|
198
|
+
* <span data-testid="ancestor">
|
|
199
|
+
* <span data-testid="descendant"></span>
|
|
200
|
+
* </span>
|
|
201
|
+
*
|
|
202
|
+
* const ancestor = page.getByTestId('ancestor')
|
|
203
|
+
* const descendant = page.getByTestId('descendant')
|
|
204
|
+
* const nonExistentElement = page.getByTestId('does-not-exist')
|
|
205
|
+
* await expect.element(ancestor).toContainElement(descendant)
|
|
206
|
+
* await expect.element(descendant).not.toContainElement(ancestor)
|
|
207
|
+
* await expect.element(ancestor).not.toContainElement(nonExistentElement)
|
|
208
|
+
* @see https://vitest.dev/api/browser/assertions#tocontainelement
|
|
209
|
+
*/
|
|
210
|
+
toContainElement(element: HTMLElement | SVGElement | Locator | null): R
|
|
211
|
+
/**
|
|
212
|
+
* @description
|
|
213
|
+
* Assert whether a string representing a HTML element is contained in another element.
|
|
214
|
+
* @example
|
|
215
|
+
* <span data-testid="parent"><span data-testid="child"></span></span>
|
|
216
|
+
*
|
|
217
|
+
* const parent = page.getByTestId('parent')
|
|
218
|
+
* await expect.element(parent).toContainHTML('<span data-testid="child"></span>')
|
|
219
|
+
* @see https://vitest.dev/api/browser/assertions#tocontainhtml
|
|
220
|
+
*/
|
|
221
|
+
toContainHTML(htmlText: string): R
|
|
222
|
+
/**
|
|
223
|
+
* @description
|
|
224
|
+
* Allows you to check if a given element has an attribute or not.
|
|
225
|
+
*
|
|
226
|
+
* You can also optionally check that the attribute has a specific expected value or partial match using
|
|
227
|
+
* [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring) or
|
|
228
|
+
* [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
|
|
229
|
+
* @example
|
|
230
|
+
* <button
|
|
231
|
+
* data-testid="ok-button"
|
|
232
|
+
* type="submit"
|
|
233
|
+
* disabled
|
|
234
|
+
* >
|
|
235
|
+
* ok
|
|
236
|
+
* </button>
|
|
237
|
+
*
|
|
238
|
+
* await expect.element(button).toHaveAttribute('disabled')
|
|
239
|
+
* await expect.element(button).toHaveAttribute('type', 'submit')
|
|
240
|
+
* await expect.element(button).not.toHaveAttribute('type', 'button')
|
|
241
|
+
* @see https://vitest.dev/api/browser/assertions#tohaveattribute
|
|
242
|
+
*/
|
|
243
|
+
toHaveAttribute(attr: string, value?: unknown): R
|
|
244
|
+
/**
|
|
245
|
+
* @description
|
|
246
|
+
* Check whether the given element has certain classes within its `class` attribute.
|
|
247
|
+
*
|
|
248
|
+
* You must provide at least one class, unless you are asserting that an element does not have any classes.
|
|
249
|
+
* @example
|
|
250
|
+
* <button
|
|
251
|
+
* data-testid="delete-button"
|
|
252
|
+
* class="btn xs btn-danger"
|
|
253
|
+
* >
|
|
254
|
+
* delete item
|
|
255
|
+
* </button>
|
|
256
|
+
*
|
|
257
|
+
* <div data-testid="no-classes">no classes</div>
|
|
258
|
+
*
|
|
259
|
+
* const deleteButton = page.getByTestId('delete-button')
|
|
260
|
+
* const noClasses = page.getByTestId('no-classes')
|
|
261
|
+
* await expect.element(deleteButton).toHaveClass('btn')
|
|
262
|
+
* await expect.element(deleteButton).toHaveClass('btn-danger xs')
|
|
263
|
+
* await expect.element(deleteButton).toHaveClass(/danger/, 'xs')
|
|
264
|
+
* await expect.element(deleteButton).toHaveClass('btn xs btn-danger', {exact: true})
|
|
265
|
+
* await expect.element(deleteButton).not.toHaveClass('btn xs btn-danger', {exact: true})
|
|
266
|
+
* await expect.element(noClasses).not.toHaveClass()
|
|
267
|
+
* @see https://vitest.dev/api/browser/assertions#tohaveclass
|
|
268
|
+
*/
|
|
269
|
+
toHaveClass(...classNames:
|
|
270
|
+
| (string | RegExp)[]
|
|
271
|
+
| [string, options?: {exact: boolean}]
|
|
272
|
+
| [string, string, options?: {exact: boolean}]
|
|
273
|
+
| [string, string, string, options?: {exact: boolean}]
|
|
274
|
+
| [string, string, string, string, options?: {exact: boolean}]
|
|
275
|
+
| [string, string, string, string, string, options?: {exact: boolean}]
|
|
276
|
+
| [string, string, string, string, string, string, options?: {exact: boolean}]
|
|
277
|
+
| [string, string, string, string, string, string, string, options?: {exact: boolean}]
|
|
278
|
+
| [string, string, string, string, string, string, string, string, options?: {exact: boolean}]
|
|
279
|
+
| [string, string, string, string, string, string, string, string, string, options?: {exact: boolean}]
|
|
280
|
+
): R
|
|
281
|
+
/**
|
|
282
|
+
* @description
|
|
283
|
+
* This allows you to check whether the given form element has the specified displayed value (the one the
|
|
284
|
+
* end user will see). It accepts <input>, <select> and <textarea> elements with the exception of <input type="checkbox">
|
|
285
|
+
* and <input type="radio">, which can be meaningfully matched only using toBeChecked or toHaveFormValues.
|
|
286
|
+
* @example
|
|
287
|
+
* <label for="input-example">First name</label>
|
|
288
|
+
* <input type="text" id="input-example" value="Luca" />
|
|
289
|
+
*
|
|
290
|
+
* <label for="textarea-example">Description</label>
|
|
291
|
+
* <textarea id="textarea-example">An example description here.</textarea>
|
|
292
|
+
*
|
|
293
|
+
* <label for="single-select-example">Fruit</label>
|
|
294
|
+
* <select id="single-select-example">
|
|
295
|
+
* <option value="">Select a fruit...</option>
|
|
296
|
+
* <option value="banana">Banana</option>
|
|
297
|
+
* <option value="ananas">Ananas</option>
|
|
298
|
+
* <option value="avocado">Avocado</option>
|
|
299
|
+
* </select>
|
|
300
|
+
*
|
|
301
|
+
* <label for="multiple-select-example">Fruits</label>
|
|
302
|
+
* <select id="multiple-select-example" multiple>
|
|
303
|
+
* <option value="">Select a fruit...</option>
|
|
304
|
+
* <option value="banana" selected>Banana</option>
|
|
305
|
+
* <option value="ananas">Ananas</option>
|
|
306
|
+
* <option value="avocado" selected>Avocado</option>
|
|
307
|
+
* </select>
|
|
308
|
+
*
|
|
309
|
+
* const input = page.getByLabelText('First name')
|
|
310
|
+
* const textarea = page.getByLabelText('Description')
|
|
311
|
+
* const selectSingle = page.getByLabelText('Fruit')
|
|
312
|
+
* const selectMultiple = page.getByLabelText('Fruits')
|
|
313
|
+
*
|
|
314
|
+
* await expect.element(input).toHaveDisplayValue('Luca')
|
|
315
|
+
* await expect.element(textarea).toHaveDisplayValue('An example description here.')
|
|
316
|
+
* await expect.element(selectSingle).toHaveDisplayValue('Select a fruit...')
|
|
317
|
+
* await expect.element(selectMultiple).toHaveDisplayValue(['Banana', 'Avocado'])
|
|
318
|
+
*
|
|
319
|
+
* @see https://vitest.dev/api/browser/assertions#tohavedisplayvalue
|
|
320
|
+
*/
|
|
321
|
+
toHaveDisplayValue(value: string | number | RegExp | Array<string | RegExp | number>): R
|
|
322
|
+
/**
|
|
323
|
+
* @description
|
|
324
|
+
* Assert whether an element has focus or not.
|
|
325
|
+
* @example
|
|
326
|
+
* <div>
|
|
327
|
+
* <input type="text" data-testid="element-to-focus" />
|
|
328
|
+
* </div>
|
|
329
|
+
*
|
|
330
|
+
* const input = page.getByTestId('element-to-focus')
|
|
331
|
+
* input.element().focus()
|
|
332
|
+
* await expect.element(input).toHaveFocus()
|
|
333
|
+
* input.element().blur()
|
|
334
|
+
* await expect.element(input).not.toHaveFocus()
|
|
335
|
+
* @see https://vitest.dev/api/browser/assertions#tohavefocus
|
|
336
|
+
*/
|
|
337
|
+
toHaveFocus(): R
|
|
338
|
+
/**
|
|
339
|
+
* @description
|
|
340
|
+
* Check if a form or fieldset contains form controls for each given name, and having the specified value.
|
|
341
|
+
*
|
|
342
|
+
* Can only be invoked on a form or fieldset element.
|
|
343
|
+
* @example
|
|
344
|
+
* <form data-testid="login-form">
|
|
345
|
+
* <input type="text" name="username" value="jane.doe" />
|
|
346
|
+
* <input type="password" name="password" value="123" />
|
|
347
|
+
* <input type="checkbox" name="rememberMe" checked />
|
|
348
|
+
* <button type="submit">Sign in</button>
|
|
349
|
+
* </form>
|
|
350
|
+
*
|
|
351
|
+
* await expect.element(page.getByTestId('login-form')).toHaveFormValues({
|
|
352
|
+
* username: 'jane.doe',
|
|
353
|
+
* rememberMe: true,
|
|
354
|
+
* })
|
|
355
|
+
* @see https://vitest.dev/api/browser/assertions#tohaveformvalues
|
|
356
|
+
*/
|
|
357
|
+
toHaveFormValues(expectedValues: Record<string, unknown>): R
|
|
358
|
+
/**
|
|
359
|
+
* @description
|
|
360
|
+
* Check if an element has specific css properties with specific values applied.
|
|
361
|
+
*
|
|
362
|
+
* Only matches if the element has *all* the expected properties applied, not just some of them.
|
|
363
|
+
* @example
|
|
364
|
+
* <button
|
|
365
|
+
* data-testid="submit-button"
|
|
366
|
+
* style="background-color: green; display: none"
|
|
367
|
+
* >
|
|
368
|
+
* submit
|
|
369
|
+
* </button>
|
|
370
|
+
*
|
|
371
|
+
* const button = page.getByTestId('submit-button')
|
|
372
|
+
* await expect.element(button).toHaveStyle('background-color: green')
|
|
373
|
+
* await expect.element(button).toHaveStyle({
|
|
374
|
+
* 'background-color': 'green',
|
|
375
|
+
* display: 'none'
|
|
376
|
+
* })
|
|
377
|
+
* @see https://vitest.dev/api/browser/assertions#tohavestyle
|
|
378
|
+
*/
|
|
379
|
+
toHaveStyle(css: string | Partial<CSSStyleDeclaration>): R
|
|
380
|
+
/**
|
|
381
|
+
* @description
|
|
382
|
+
* Check whether the given element has a text content or not.
|
|
383
|
+
*
|
|
384
|
+
* When a string argument is passed through, it will perform a partial case-sensitive match to the element
|
|
385
|
+
* content.
|
|
386
|
+
*
|
|
387
|
+
* To perform a case-insensitive match, you can use a RegExp with the `/i` modifier.
|
|
388
|
+
*
|
|
389
|
+
* If you want to match the whole content, you can use a RegExp to do it.
|
|
390
|
+
* @example
|
|
391
|
+
* <span data-testid="text-content">Text Content</span>
|
|
392
|
+
*
|
|
393
|
+
* const element = page.getByTestId('text-content')
|
|
394
|
+
* await expect.element(element).toHaveTextContent('Content')
|
|
395
|
+
* // to match the whole content
|
|
396
|
+
* await expect.element(element).toHaveTextContent(/^Text Content$/)
|
|
397
|
+
* // to use case-insensitive match
|
|
398
|
+
* await expect.element(element).toHaveTextContent(/content$/i)
|
|
399
|
+
* await expect.element(element).not.toHaveTextContent('content')
|
|
400
|
+
* @see https://vitest.dev/api/browser/assertions#tohavetextcontent
|
|
401
|
+
*/
|
|
402
|
+
toHaveTextContent(
|
|
403
|
+
text: string | number | RegExp,
|
|
404
|
+
options?: {normalizeWhitespace: boolean},
|
|
405
|
+
): R
|
|
406
|
+
/**
|
|
407
|
+
* @description
|
|
408
|
+
* Check whether the given form element has the specified value.
|
|
409
|
+
*
|
|
410
|
+
* Accepts `<input>`, `<select>`, and `<textarea>` elements with the exception of `<input type="checkbox">` and
|
|
411
|
+
* `<input type="radiobox">`, which can be matched only using
|
|
412
|
+
* [toBeChecked](https://vitest.dev/api/browser/assertions#tobechecked) or
|
|
413
|
+
* [toHaveFormValues](https://vitest.dev/api/browser/assertions#tohaveformvalues).
|
|
414
|
+
* @example
|
|
415
|
+
* <input
|
|
416
|
+
* type="number"
|
|
417
|
+
* value="5"
|
|
418
|
+
* data-testid="input-number" />
|
|
419
|
+
*
|
|
420
|
+
* const numberInput = page.getByTestId('input-number')
|
|
421
|
+
* await expect.element(numberInput).toHaveValue(5)
|
|
422
|
+
* @see https://vitest.dev/api/browser/assertions#tohavevalue
|
|
423
|
+
*/
|
|
424
|
+
toHaveValue(value?: string | string[] | number | null): R
|
|
425
|
+
/**
|
|
426
|
+
* @description
|
|
427
|
+
* Assert whether the given element is checked.
|
|
428
|
+
*
|
|
429
|
+
* It accepts an `input` of type `checkbox` or `radio` and elements with a `role` of `radio` with a valid
|
|
430
|
+
* `aria-checked` attribute of "true" or "false".
|
|
431
|
+
* @example
|
|
432
|
+
* <input
|
|
433
|
+
* type="checkbox"
|
|
434
|
+
* checked
|
|
435
|
+
* data-testid="input-checkbox" />
|
|
436
|
+
* <input
|
|
437
|
+
* type="radio"
|
|
438
|
+
* value="foo"
|
|
439
|
+
* data-testid="input-radio" />
|
|
440
|
+
*
|
|
441
|
+
* const inputCheckbox = page.getByTestId('input-checkbox')
|
|
442
|
+
* const inputRadio = page.getByTestId('input-radio')
|
|
443
|
+
* await expect.element(inputCheckbox).toBeChecked()
|
|
444
|
+
* await expect.element(inputRadio).not.toBeChecked()
|
|
445
|
+
* @see https://vitest.dev/api/browser/assertions#tobechecked
|
|
446
|
+
*/
|
|
447
|
+
toBeChecked(): R
|
|
448
|
+
/**
|
|
449
|
+
* @description
|
|
450
|
+
* This allows to assert that an element has the expected [accessible description](https://w3c.github.io/accname/).
|
|
451
|
+
*
|
|
452
|
+
* You can pass the exact string of the expected accessible description, or you can make a
|
|
453
|
+
* partial match passing a regular expression, or by using either
|
|
454
|
+
* [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
|
|
455
|
+
* or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
|
|
456
|
+
* @example
|
|
457
|
+
* <a data-testid="link" href="/" aria-label="Home page" title="A link to start over">Start</a>
|
|
458
|
+
* <a data-testid="extra-link" href="/about" aria-label="About page">About</a>
|
|
459
|
+
* <img src="avatar.jpg" data-testid="avatar" alt="User profile pic" />
|
|
460
|
+
* <img src="logo.jpg" data-testid="logo" alt="Company logo" aria-describedby="t1" />
|
|
461
|
+
* <span id="t1" role="presentation">The logo of Our Company</span>
|
|
462
|
+
*
|
|
463
|
+
* await expect.element(page.getByTestId('link')).toHaveAccessibleDescription()
|
|
464
|
+
* await expect.element(page.getByTestId('link')).toHaveAccessibleDescription('A link to start over')
|
|
465
|
+
* await expect.element(page.getByTestId('link')).not.toHaveAccessibleDescription('Home page')
|
|
466
|
+
* await expect.element(page.getByTestId('extra-link')).not.toHaveAccessibleDescription()
|
|
467
|
+
* await expect.element(page.getByTestId('avatar')).not.toHaveAccessibleDescription()
|
|
468
|
+
* await expect.element(page.getByTestId('logo')).not.toHaveAccessibleDescription('Company logo')
|
|
469
|
+
* await expect.element(page.getByTestId('logo')).toHaveAccessibleDescription('The logo of Our Company')
|
|
470
|
+
* @see https://vitest.dev/api/browser/assertions#tohaveaccessibledescription
|
|
471
|
+
*/
|
|
472
|
+
toHaveAccessibleDescription(text?: string | RegExp | E): R
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* @description
|
|
476
|
+
* This allows you to assert that an element has the expected
|
|
477
|
+
* [accessible error message](https://w3c.github.io/aria/#aria-errormessage).
|
|
478
|
+
*
|
|
479
|
+
* You can pass the exact string of the expected accessible error message.
|
|
480
|
+
* Alternatively, you can perform a partial match by passing a regular expression
|
|
481
|
+
* or by using either
|
|
482
|
+
* [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
|
|
483
|
+
* or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* <input aria-label="Has Error" aria-invalid="true" aria-errormessage="error-message" />
|
|
487
|
+
* <div id="error-message" role="alert">This field is invalid</div>
|
|
488
|
+
*
|
|
489
|
+
* <input aria-label="No Error Attributes" />
|
|
490
|
+
* <input aria-label="Not Invalid" aria-invalid="false" aria-errormessage="error-message" />
|
|
491
|
+
*
|
|
492
|
+
* // Inputs with Valid Error Messages
|
|
493
|
+
* await expect.element(page.getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage()
|
|
494
|
+
* await expect.element(page.getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage('This field is invalid')
|
|
495
|
+
* await expect.element(page.getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage(/invalid/i)
|
|
496
|
+
* await expect.element(
|
|
497
|
+
* page.getByRole('textbox', {name: 'Has Error'}),
|
|
498
|
+
* ).not.toHaveAccessibleErrorMessage('This field is absolutely correct!')
|
|
499
|
+
*
|
|
500
|
+
* // Inputs without Valid Error Messages
|
|
501
|
+
* await expect.element(
|
|
502
|
+
* page.getByRole('textbox', {name: 'No Error Attributes'}),
|
|
503
|
+
* ).not.toHaveAccessibleErrorMessage()
|
|
504
|
+
*
|
|
505
|
+
* await expect.element(
|
|
506
|
+
* page.getByRole('textbox', {name: 'Not Invalid'}),
|
|
507
|
+
* ).not.toHaveAccessibleErrorMessage()
|
|
508
|
+
*
|
|
509
|
+
* @see https://vitest.dev/api/browser/assertions#tohaveaccessibleerrormessage
|
|
510
|
+
*/
|
|
511
|
+
toHaveAccessibleErrorMessage(text?: string | RegExp | E): R
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* @description
|
|
515
|
+
* This allows to assert that an element has the expected [accessible name](https://w3c.github.io/accname/).
|
|
516
|
+
* It is useful, for instance, to assert that form elements and buttons are properly labelled.
|
|
517
|
+
*
|
|
518
|
+
* You can pass the exact string of the expected accessible name, or you can make a
|
|
519
|
+
* partial match passing a regular expression, or by using either
|
|
520
|
+
* [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
|
|
521
|
+
* or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
|
|
522
|
+
* @example
|
|
523
|
+
* <img data-testid="img-alt" src="" alt="Test alt" />
|
|
524
|
+
* <img data-testid="img-empty-alt" src="" alt="" />
|
|
525
|
+
* <svg data-testid="svg-title"><title>Test title</title></svg>
|
|
526
|
+
* <button data-testid="button-img-alt"><img src="" alt="Test" /></button>
|
|
527
|
+
* <p><img data-testid="img-paragraph" src="" alt="" /> Test content</p>
|
|
528
|
+
* <button data-testid="svg-button"><svg><title>Test</title></svg></p>
|
|
529
|
+
* <div><svg data-testid="svg-without-title"></svg></div>
|
|
530
|
+
* <input data-testid="input-title" title="test" />
|
|
531
|
+
*
|
|
532
|
+
* await expect.element(page.getByTestId('img-alt')).toHaveAccessibleName('Test alt')
|
|
533
|
+
* await expect.element(page.getByTestId('img-empty-alt')).not.toHaveAccessibleName()
|
|
534
|
+
* await expect.element(page.getByTestId('svg-title')).toHaveAccessibleName('Test title')
|
|
535
|
+
* await expect.element(page.getByTestId('button-img-alt')).toHaveAccessibleName()
|
|
536
|
+
* await expect.element(page.getByTestId('img-paragraph')).not.toHaveAccessibleName()
|
|
537
|
+
* await expect.element(page.getByTestId('svg-button')).toHaveAccessibleName()
|
|
538
|
+
* await expect.element(page.getByTestId('svg-without-title')).not.toHaveAccessibleName()
|
|
539
|
+
* await expect.element(page.getByTestId('input-title')).toHaveAccessibleName()
|
|
540
|
+
* @see https://vitest.dev/api/browser/assertions#tohaveaccessiblename
|
|
541
|
+
*/
|
|
542
|
+
toHaveAccessibleName(text?: string | RegExp | E): R
|
|
543
|
+
/**
|
|
544
|
+
* @description
|
|
545
|
+
* This allows you to assert that an element has the expected
|
|
546
|
+
* [role](https://www.w3.org/TR/html-aria/#docconformance).
|
|
547
|
+
*
|
|
548
|
+
* This is useful in cases where you already have access to an element via
|
|
549
|
+
* some query other than the role itself, and want to make additional
|
|
550
|
+
* assertions regarding its accessibility.
|
|
551
|
+
*
|
|
552
|
+
* The role can match either an explicit role (via the `role` attribute), or
|
|
553
|
+
* an implicit one via the [implicit ARIA
|
|
554
|
+
* semantics](https://www.w3.org/TR/html-aria/).
|
|
555
|
+
*
|
|
556
|
+
* Note: roles are matched literally by string equality, without inheriting
|
|
557
|
+
* from the ARIA role hierarchy. As a result, querying a superclass role
|
|
558
|
+
* like 'checkbox' will not include elements with a subclass role like
|
|
559
|
+
* 'switch'.
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* <button data-testid="button">Continue</button>
|
|
563
|
+
* <div role="button" data-testid="button-explicit">Continue</button>
|
|
564
|
+
* <button role="switch button" data-testid="button-explicit-multiple">Continue</button>
|
|
565
|
+
* <a href="/about" data-testid="link">About</a>
|
|
566
|
+
* <a data-testid="link-invalid">Invalid link<a/>
|
|
567
|
+
*
|
|
568
|
+
* await expect.element(page.getByTestId('button')).toHaveRole('button')
|
|
569
|
+
* await expect.element(page.getByTestId('button-explicit')).toHaveRole('button')
|
|
570
|
+
* await expect.element(page.getByTestId('button-explicit-multiple')).toHaveRole('button')
|
|
571
|
+
* await expect.element(page.getByTestId('button-explicit-multiple')).toHaveRole('switch')
|
|
572
|
+
* await expect.element(page.getByTestId('link')).toHaveRole('link')
|
|
573
|
+
* await expect.element(page.getByTestId('link-invalid')).not.toHaveRole('link')
|
|
574
|
+
* await expect.element(page.getByTestId('link-invalid')).toHaveRole('generic')
|
|
575
|
+
*
|
|
576
|
+
* @see https://vitest.dev/api/browser/assertions#tohaverole
|
|
577
|
+
*/
|
|
578
|
+
toHaveRole(
|
|
579
|
+
// Get autocomplete for ARIARole union types, while still supporting another string
|
|
580
|
+
// Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939
|
|
581
|
+
role: ARIARole | (string & {}),
|
|
582
|
+
): R
|
|
583
|
+
/**
|
|
584
|
+
* @description
|
|
585
|
+
* This allows you to check whether the given element is partially checked.
|
|
586
|
+
* It accepts an input of type checkbox and elements with a role of checkbox
|
|
587
|
+
* with a aria-checked="mixed", or input of type checkbox with indeterminate
|
|
588
|
+
* set to true
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* <input type="checkbox" aria-checked="mixed" data-testid="aria-checkbox-mixed" />
|
|
592
|
+
* <input type="checkbox" checked data-testid="input-checkbox-checked" />
|
|
593
|
+
* <input type="checkbox" data-testid="input-checkbox-unchecked" />
|
|
594
|
+
* <div role="checkbox" aria-checked="true" data-testid="aria-checkbox-checked" />
|
|
595
|
+
* <div
|
|
596
|
+
* role="checkbox"
|
|
597
|
+
* aria-checked="false"
|
|
598
|
+
* data-testid="aria-checkbox-unchecked"
|
|
599
|
+
* />
|
|
600
|
+
* <input type="checkbox" data-testid="input-checkbox-indeterminate" />
|
|
601
|
+
*
|
|
602
|
+
* const ariaCheckboxMixed = getByTestId('aria-checkbox-mixed')
|
|
603
|
+
* const inputCheckboxChecked = getByTestId('input-checkbox-checked')
|
|
604
|
+
* const inputCheckboxUnchecked = getByTestId('input-checkbox-unchecked')
|
|
605
|
+
* const ariaCheckboxChecked = getByTestId('aria-checkbox-checked')
|
|
606
|
+
* const ariaCheckboxUnchecked = getByTestId('aria-checkbox-unchecked')
|
|
607
|
+
* const inputCheckboxIndeterminate = getByTestId('input-checkbox-indeterminate')
|
|
608
|
+
*
|
|
609
|
+
* await expect.element(ariaCheckboxMixed).toBePartiallyChecked()
|
|
610
|
+
* await expect.element(inputCheckboxChecked).not.toBePartiallyChecked()
|
|
611
|
+
* await expect.element(inputCheckboxUnchecked).not.toBePartiallyChecked()
|
|
612
|
+
* await expect.element(ariaCheckboxChecked).not.toBePartiallyChecked()
|
|
613
|
+
* await expect.element(ariaCheckboxUnchecked).not.toBePartiallyChecked()
|
|
614
|
+
*
|
|
615
|
+
* inputCheckboxIndeterminate.indeterminate = true
|
|
616
|
+
* await expect.element(inputCheckboxIndeterminate).toBePartiallyChecked()
|
|
617
|
+
* @see https://vitest.dev/api/browser/assertions#tobepartiallychecked
|
|
618
|
+
*/
|
|
619
|
+
toBePartiallyChecked(): R
|
|
620
|
+
/**
|
|
621
|
+
* @description
|
|
622
|
+
* This allows to assert that an element has a
|
|
623
|
+
* [text selection](https://developer.mozilla.org/en-US/docs/Web/API/Selection).
|
|
624
|
+
*
|
|
625
|
+
* This is useful to check if text or part of the text is selected within an
|
|
626
|
+
* element. The element can be either an input of type text, a textarea, or any
|
|
627
|
+
* other element that contains text, such as a paragraph, span, div etc.
|
|
628
|
+
*
|
|
629
|
+
* NOTE: the expected selection is a string, it does not allow to check for
|
|
630
|
+
* selection range indices.
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* <div>
|
|
634
|
+
* <input type="text" value="text selected text" data-testid="text" />
|
|
635
|
+
* <textarea data-testid="textarea">text selected text</textarea>
|
|
636
|
+
* <p data-testid="prev">prev</p>
|
|
637
|
+
* <p data-testid="parent">text <span data-testid="child">selected</span> text</p>
|
|
638
|
+
* <p data-testid="next">next</p>
|
|
639
|
+
* </div>
|
|
640
|
+
*
|
|
641
|
+
* page.getByTestId('text').element().setSelectionRange(5, 13)
|
|
642
|
+
* await expect.element(page.getByTestId('text')).toHaveSelection('selected')
|
|
643
|
+
*
|
|
644
|
+
* page.getByTestId('textarea').element().setSelectionRange(0, 5)
|
|
645
|
+
* await expect.element('textarea').toHaveSelection('text ')
|
|
646
|
+
*
|
|
647
|
+
* const selection = document.getSelection()
|
|
648
|
+
* const range = document.createRange()
|
|
649
|
+
* selection.removeAllRanges()
|
|
650
|
+
* selection.empty()
|
|
651
|
+
* selection.addRange(range)
|
|
652
|
+
*
|
|
653
|
+
* // selection of child applies to the parent as well
|
|
654
|
+
* range.selectNodeContents(page.getByTestId('child').element())
|
|
655
|
+
* await expect.element(page.getByTestId('child')).toHaveSelection('selected')
|
|
656
|
+
* await expect.element(page.getByTestId('parent')).toHaveSelection('selected')
|
|
657
|
+
*
|
|
658
|
+
* // selection that applies from prev all, parent text before child, and part child.
|
|
659
|
+
* range.setStart(page.getByTestId('prev').element(), 0)
|
|
660
|
+
* range.setEnd(page.getByTestId('child').element().childNodes[0], 3)
|
|
661
|
+
* await expect.element(page.queryByTestId('prev')).toHaveSelection('prev')
|
|
662
|
+
* await expect.element(page.queryByTestId('child')).toHaveSelection('sel')
|
|
663
|
+
* await expect.element(page.queryByTestId('parent')).toHaveSelection('text sel')
|
|
664
|
+
* await expect.element(page.queryByTestId('next')).not.toHaveSelection()
|
|
665
|
+
*
|
|
666
|
+
* // selection that applies from part child, parent text after child and part next.
|
|
667
|
+
* range.setStart(page.getByTestId('child').element().childNodes[0], 3)
|
|
668
|
+
* range.setEnd(page.getByTestId('next').element().childNodes[0], 2)
|
|
669
|
+
* await expect.element(page.queryByTestId('child')).toHaveSelection('ected')
|
|
670
|
+
* await expect.element(page.queryByTestId('parent')).toHaveSelection('ected text')
|
|
671
|
+
* await expect.element(page.queryByTestId('prev')).not.toHaveSelection()
|
|
672
|
+
* await expect.element(page.queryByTestId('next')).toHaveSelection('ne')
|
|
673
|
+
*
|
|
674
|
+
* @see https://vitest.dev/api/browser/assertions#tohaveselection
|
|
675
|
+
*/
|
|
676
|
+
toHaveSelection(selection?: string): R
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* @description
|
|
680
|
+
* This assertion allows you to perform visual regression testing by comparing
|
|
681
|
+
* screenshots of elements or pages against stored reference images.
|
|
682
|
+
*
|
|
683
|
+
* When differences are detected beyond the configured threshold, the test fails.
|
|
684
|
+
* To help identify the changes, the assertion generates:
|
|
685
|
+
*
|
|
686
|
+
* - The actual screenshot captured during the test
|
|
687
|
+
* - The expected reference screenshot
|
|
688
|
+
* - A diff image highlighting the differences (when possible)
|
|
689
|
+
*
|
|
690
|
+
* @example
|
|
691
|
+
* <button data-testid="button">Fancy Button</button>
|
|
692
|
+
*
|
|
693
|
+
* // basic usage, auto-generates screenshot name
|
|
694
|
+
* await expect.element(getByTestId('button')).toMatchScreenshot()
|
|
695
|
+
*
|
|
696
|
+
* // with custom name
|
|
697
|
+
* await expect.element(getByTestId('button')).toMatchScreenshot('fancy-button')
|
|
698
|
+
*
|
|
699
|
+
* // with options
|
|
700
|
+
* await expect.element(getByTestId('button')).toMatchScreenshot({
|
|
701
|
+
* comparatorName: 'pixelmatch',
|
|
702
|
+
* comparatorOptions: {
|
|
703
|
+
* allowedMismatchedPixelRatio: 0.01,
|
|
704
|
+
* },
|
|
705
|
+
* })
|
|
706
|
+
*
|
|
707
|
+
* // with both name and options
|
|
708
|
+
* await expect.element(getByTestId('button')).toMatchScreenshot('fancy-button', {
|
|
709
|
+
* comparatorName: 'pixelmatch',
|
|
710
|
+
* comparatorOptions: {
|
|
711
|
+
* allowedMismatchedPixelRatio: 0.01,
|
|
712
|
+
* },
|
|
713
|
+
* })
|
|
714
|
+
*
|
|
715
|
+
* @see https://vitest.dev/api/browser/assertions#tomatchscreenshot
|
|
716
|
+
*/
|
|
717
|
+
toMatchScreenshot<ComparatorName extends keyof ScreenshotComparatorRegistry>(
|
|
718
|
+
options?: ScreenshotMatcherOptions<ComparatorName>,
|
|
719
|
+
): Promise<R>
|
|
720
|
+
toMatchScreenshot<ComparatorName extends keyof ScreenshotComparatorRegistry>(
|
|
721
|
+
name?: string,
|
|
722
|
+
options?: ScreenshotMatcherOptions<ComparatorName>,
|
|
723
|
+
): Promise<R>
|
|
724
|
+
}
|