-
Notifications
You must be signed in to change notification settings - Fork 17
Testing Resource Component #60
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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" />); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Little confused why you are rendering a div in this test. I would think you would need to render the Resource component itself? |
||
const resourceName = screen.getByTestId("name"); | ||
expect(resourceName).toBeInTheDocument(); | ||
}); | ||
// screen.debug(); | ||
|
||
test("resource body", () => { | ||
render(<div data-testid="body" />); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here. I would think you would have to render the Resource component first and then just have the lines to get the resourceBody here and verify it is there. |
||
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove all the commented out code from here? |
||
// <MemoryRouter history={history}> | ||
// <Link to={`/resources/1`}>More info</Link> | ||
// </MemoryRouter> | ||
// ); | ||
|
||
// fireEvent.click(getByText('More info')); | ||
// expect(history.push).toHaveBeenCalledWith(`resources/1`); | ||
// }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you had a merge conflict here which inserts these lines. You will need to remove them - lines 9, 11 and 13. I believe this pull request build is failing because of it.