Replace direct rendering with react testing library by vitest-browser-react

This commit is contained in:
Alejandro Celaya
2026-08-16 19:59:44 +02:00
parent 585d7c6f63
commit 260bdb260c
13 changed files with 86 additions and 54 deletions

View File

@@ -1,6 +1,6 @@
import { render } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { ContainerProvider, useDependencies } from '../../src/container/context';
import { render } from '../__helpers__/setUpTest.tsx';
describe('context', () => {
describe('useDependencies', () => {
@@ -12,24 +12,24 @@ describe('context', () => {
return null;
}
it('throws when used outside of ContainerProvider', () => {
expect(() => render(<TestComponent name="foo" />)).toThrow(
it('throws when used outside of ContainerProvider', async () => {
await expect(() => render(<TestComponent name="foo" />)).rejects.toThrow(
'You cannot use "useDependencies" outside of a ContainerProvider',
);
});
it('throws when requested dependency is not found in container', () => {
expect(() =>
it('throws when requested dependency is not found in container', async () => {
await expect(() =>
render(
<ContainerProvider value={fromPartial({})}>
<TestComponent name="foo" />
</ContainerProvider>,
),
).toThrow('Dependency with name "foo" not found in container');
).rejects.toThrow('Dependency with name "foo" not found in container');
});
it('gets dependency from container', () => {
render(
it('gets dependency from container', async () => {
await render(
<ContainerProvider value={fromPartial({ foo: 'the dependency' })}>
<TestComponent name="foo" />
</ContainerProvider>,