Skip to content

Commit

Permalink
Add test for TragetGroupsStep
Browse files Browse the repository at this point in the history
I had some issues with React Testing Library for TS
testing-library/react-testing-library#610
  • Loading branch information
th3mon committed Oct 2, 2020
1 parent 23d91b1 commit 830620b
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 8 deletions.
189 changes: 189 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"devDependencies": {
"@types/react-router-dom": "^5.1.5",
"@types/yup": "^0.29.7",
"msw": "^0.21.2",
"node-sass": "^4.14.1"
}
}
35 changes: 27 additions & 8 deletions client/src/app/pages/calculator/calculator.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
import React from 'react';
import { render } from '@testing-library/react';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
import { cleanup, render } from '@testing-library/react';
import { Calculator } from './calculator';

test('renders standard bonuses header', () => {
const { getByText } = render(<Calculator />);
const header = getByText(/standardowe bonusy/i);
const server = setupServer(
rest.get('/api/bonuses', (req, res, ctx) => {
return res(ctx.json({ greeting: 'hello there' }));
})
);

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

expect(header).toBeInTheDocument();
afterEach(cleanup);

test('renders standard bonuses header', async () => {
const { getByText } = render(<Calculator />);
getByText(/standardowe bonusy/i);
});

test('renders additional bonuses header', () => {
const { getByText } = render(<Calculator />);
const header = getByText(/dodatkowe bonusy/i);

expect(header).toBeInTheDocument();
getByText(/dodatkowe bonusy/i);
});

// test('renders target group', async () => {
// const { getByText } = render(<Calculator />);
// const nextButton = getByText(/dalej/i);

// fireEvent.click(nextButton);
// // https://github.com/testing-library/react-testing-library/issues/610
// await waitFor(() => getByText(/Target Group/i));
// });

0 comments on commit 830620b

Please sign in to comment.