-
Notifications
You must be signed in to change notification settings - Fork 970
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
fix cell generated test template #1142
Conversation
Looking further, I found this original Cell test template sketch: Now looking into using the mock file to do something closer to ^^ |
closes #629 |
@peterp This one is ready for review -- any suggests about other/better ways to incorporate the existing mock file into the tests? Also, I took some notes from Robert for specific Jest queries used. Please confirm that's what you'd like to see in the template. |
Hey @thedavidprice Rendering the individual parts of a cell is kind of testing implementation details. What I would love to see is something more like in #629, but with MSW instead of Something like this: import { render, screen, graphql } from '@redwoodjs/testing'
import BlogPostCell from './BlogPostCell'
describe('BlogPostCell', () => {
it('renders post succesfully', async () => {
graphql.query('GetPost', (req, res, ctx) => {
return res(
ctx.data({
post: {
title: 'Post Title',
id: 'id-123',
body: 'Test',
__typename: 'Post',
},
})
)
})
render(<BlogPostCell id="id-123" />)
expect(await screen.findByText(/Post Title/)).toBeInTheDocument()
})
it('handles errors', async () => {
graphql.query('GetPost', (req, res, ctx) => {
return res(
ctx.errors([
{
message: 'Whoops!',
},
])
)
})
render(<BlogPostCell id={1} />)
expect(await screen.findByText(/Whoops!/)).toBeInTheDocument()
})
}) I'm not so familiar with the generator outputs, so I'm not sure if this is possible, but I think it is! This way the test is closer to the real world use of Does that make sense? Let me know if you'd like me to take a stab at writing the generator template! |
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.
I think @RobertBroersma's suggestion make sense, but this pull-request may have been focusing on fixing the test templates. Maybe we should open another issue for improving them?
@peterp looping you in on this one. Dom and I are coordinating the generated tests that need to be fixed/completed. This seemed to do the trick for cells but would welcome your eyes/improvement.