Helpers library for writing unit tests for tramvai child-app
Uses @tramvai/test-unit
under hood to create test root-app that will wrap child-app.
You can get React Component returned by child-app from return value of testChildApp
function and use for example testComponent
helper from the @tramvai/test-react
:::warning
To properly render child-app component pass as props to it its di and optionally props object, that will be passed to the underlying child-app component.
:::
import { testComponent } from '@tramvai/test-react';
import childApp from './child-app.tsx';
(async () => {
const {
childApp: { Component, di },
close,
} = await testChildApp(childApp);
const { render } = testComponent(<Component di={di} props={{ test: 'abc' }} />);
expect(render.getByTestId('from-root').textContent).toBe('Value from Root: abc');
})();
import childApp from './child-app.tsx';
(async () => {
const {
childApp: { di },
close,
} = await testChildApp(childApp);
expect(di.get(CHILD_APP_BASE_TOKEN)).toBe("I'm little child app");
})();
More examples
@inline src/testChildApp.spec.tsx