@tramvai/test-child-app
TypeScript icon, indicating that this package has built-in type declarations

2.160.1 • Public • Published

Tramvai test child-app

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.

How to

Test child-app main component render

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');
})();

Test child-app di

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

Readme

Keywords

none

Package Sidebar

Install

npm i @tramvai/test-child-app

Weekly Downloads

485

Version

2.160.1

License

Apache-2.0

Unpacked Size

10.1 kB

Total Files

8

Last publish

Collaborators

  • meskill
  • super_oleg
  • tinkoffbank