-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathResources.test.js
62 lines (51 loc) · 1.64 KB
/
Resources.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { render, screen, fireEvent } from "@testing-library/react";
import { MemoryRouter, Link } from 'react-router-dom';
import { createMemoryHistory } from 'history';
import SingleResource from '../SingleResource/SingleResource';
import Resources from "./Resources";
import Toggle from "../Toggle";
import axios from "axios";
// test.afterEach(cleanup)
describe("Resources Component", () => {
it('rendered toggle', () => {
const { getByTestId } = render(<Toggle />);
const toggle = getByTestId("toggle");
expect(toggle).toBeTruthy();
});
})
test("resource name", () => {
render(<div data-testid="name" />);
const resourceName = screen.getByTestId("name");
expect(resourceName).toBeInTheDocument();
});
// screen.debug();
test("resource body", () => {
render(<div data-testid="body" />);
const resourceBody = screen.getByTestId("body");
expect(resourceBody).toBeInTheDocument();
});
// test("link working", () => {
// const history = createMemoryHistory();
// history.push = jest.fn();
jest.mock('axios');
it('returns the first resource', async () => {
axios.get.mockResolvedValue({
data: [
{
userId: 1,
id: 1,
title: 'My First Album'
}
]
});
const resource = await SingleResource();
expect(resource).toHaveBeenCalledTimes('/resources/1');
});
// const { getByText } = render(
// <MemoryRouter history={history}>
// <Link to={`/resources/1`}>More info</Link>
// </MemoryRouter>
// );
// fireEvent.click(getByText('More info'));
// expect(history.push).toHaveBeenCalledWith(`resources/1`);
// });