Closed
Description
repository
https://github.com/shamokit/svelte-vitest-happydom-PrettyFormatPluginError
packages
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/svelte": "^4.1.0",
"happy-dom": "^14.3.1",
"svelte": "^4.2.7",
"vitest": "^1.4.0"
about
When a test fails, "PrettyFormatPluginError" may appear instead of "TestingLibraryElementError" that should appear.
I would be happy if TestingLibraryElementError would be returned.
code
Buttons.svelte
<script lang="ts">
export let name: string | undefined = undefined;
export let count: number = 0;
</script>
<button type="button">{name}</button>
<button type="button">{count}</button>
Buttons.test.ts
import { render, screen } from '@testing-library/svelte';
import { expect, test, describe } from 'vitest';
import Buttons from './Buttons.svelte';
describe('Buttons.svelte', async () => {
test('two buttons', async () => {
render(Buttons, {
name: 'Svelte',
count: 2,
});
const button = screen.getByRole('button', { name: 'Svelte' });
expect(button).toBeInTheDocument();
// PrettyFormatPluginError occurs when I write a test that intentionally fails.
const changedButton = screen.getByRole('button', { name: 'zzzz' });
expect(changedButton).toBeInTheDocument();
});
});
changedButton does not exist.
At this time, a "TestingLibraryElementError" error should be returned, but if there is an element that depends on another export let
in the component, a "PrettyFormatPluginError" will be returned.
example
<button type="button">{name}</button>
<button type="button">2</button> // not {count}
or
<button type="button">{name}</button>
→ TestingLibraryElementError(OK)
<button type="button">{name}</button>
<button type="button">{count}</button>
→ PrettyFormatPluginError(NG)
Metadata
Metadata
Assignees
Labels
No labels