import { fromPartial } from '@total-typescript/shoehorn';
import { ContainerProvider, useDependencies } from '../../src/container/context';
import { render } from '../__helpers__/setUpTest.tsx';
describe('context', () => {
describe('useDependencies', () => {
let lastDependencies: unknown[];
function TestComponent({ name }: { name: string }) {
// eslint-disable-next-line react-compiler/react-compiler
lastDependencies = useDependencies(name);
return null;
}
it('throws when used outside of ContainerProvider', async () => {
await expect(() => render()).rejects.toThrow(
'You cannot use "useDependencies" outside of a ContainerProvider',
);
});
it('throws when requested dependency is not found in container', async () => {
await expect(() =>
render(
,
),
).rejects.toThrow('Dependency with name "foo" not found in container');
});
it('gets dependency from container', async () => {
await render(
,
);
expect(lastDependencies).toEqual(['the dependency']);
});
});
});