Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): Add react-testing-library to react templates #927

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/templates/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const reactTemplate: Template = {
name: 'react',
dependencies: [
...basicTemplate.dependencies,
'@testing-library/react',
'@testing-library/jest-dom',
'@types/react',
'@types/react-dom',
'react',
Expand All @@ -21,6 +23,9 @@ const reactTemplate: Template = {
...basicTemplate.packageJson.scripts,
test: 'tsdx test --passWithNoTests',
} as PackageJson['scripts'],
jest: {
setupFilesAfterEnv: ['./jest.setup.ts'],
},
},
};

Expand Down
2 changes: 1 addition & 1 deletion templates/react-with-storybook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ tsconfig.json

#### React Testing Library

We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this.
[React Testing Library](https://testing-library.com/docs/react-testing-library/intro/) has been set up for you to help with best practices for writing React tests.

### Rollup

Expand Down
1 change: 1 addition & 0 deletions templates/react-with-storybook/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom';
12 changes: 7 additions & 5 deletions templates/react-with-storybook/test/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from 'react';
import * as ReactDOM from 'react-dom';
import { render } from '@testing-library/react';
import { Default as Thing } from '../stories/Thing.stories';

describe('Thing', () => {
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Thing />, div);
ReactDOM.unmountComponentAtNode(div);
it('renders the correct text', () => {
const { getByText } = render(<Thing />);

expect(
getByText('the snozzberries taste like snozzberries')
).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion templates/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tsconfig.json

#### React Testing Library

We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this.
[React Testing Library](https://testing-library.com/docs/react-testing-library/intro/) has been set up for you to help with best practices for writing React tests.

### Rollup

Expand Down
1 change: 1 addition & 0 deletions templates/react/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom';
12 changes: 7 additions & 5 deletions templates/react/test/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { render } from '@testing-library/react';
import { Thing } from '../src';

describe('Thing', () => {
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Thing />, div);
ReactDOM.unmountComponentAtNode(div);
it('renders the correct text', () => {
const { getByText } = render(<Thing />);

expect(
getByText('the snozzberries taste like snozzberries')
).toBeInTheDocument();
});
});