This package provides helpers for testing React components in Typescript with React Testing Library and Alsatian.
npm i alsatian-react-testing-library
import { Test, TestFixture } from "alsatian";
import { ExpectElement } from "alsatian-react-testing-library";
import { render } from "@testing-library/react";
import { MyComponent } from "./MyComponent";
configureJSDOM(); // This is important!
@TestFixture("MyComponent")
export class MyComponentTests {
@Test("should render component")
public shouldRenderComponent() {
const wrapper = render(<MyComponent />);
ExpectElement(wrapper).toMatchElement(
<div>
My components body.
</div>
);
}
}
Made with 💖 by NewOrbit in Oxfordshire, and licensed under the MIT Licence