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: React testing components #13

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sivicencio
Copy link

What?

  • Testing de componente App con React Testing Library
  • Snapshot testing de dos componentes: Home y AuthorDetail (este último incluye un request HTTP)

Why?

  • Como parte de la cápsula 34, que les permitirá a los alumnos agregar tests de frontend en su SPA

How?

  • Se utilizó el package react-testing-library que ya viene instalado con CRA para hacer un test simple de App
  • Se utilizó el package react-test-renderer para generar snapshots de componentes
  • Se hizo un mock de fetch para simular un request HTTP dentro de AuthorDetail gracias al package jest-fetch-mock

Resultado

 PASS  src/views/Home.test.jsx
  Home
    when user is not logged in
      ✓ renders the home page with log in link (29 ms)
    when user is logged in
      ✓ renders the home page with logout button (7 ms)

 PASS  src/App.test.jsx
  ✓ renders "Welcome to Gud Reads" title (161 ms)

 PASS  src/views/AuthorDetail.test.jsx
  AuthorDetail
    when user is not logged in
      ✓ renders the author data along with their books (25 ms)

Test Suites: 3 passed, 3 total
Tests:       4 passed, 4 total
Snapshots:   3 passed, 3 total
Time:        9.35 s
Ran all test suites.

@sivicencio sivicencio requested a review from meretamal July 6, 2021 06:15
@netlify
Copy link

netlify bot commented Jul 6, 2021

✔️ Deploy Preview for hopeful-pare-dc0538 ready!

🔨 Explore the source changes: f919d58

🔍 Inspect the deploy log: https://app.netlify.com/sites/hopeful-pare-dc0538/deploys/60e465b143f10e00078af49d

😎 Browse the preview: https://deploy-preview-13--hopeful-pare-dc0538.netlify.app

Comment on lines +6 to +12
function TestRouter({ path }) {
return (
<MemoryRouter initialEntries={[path]}>
<Routes />
</MemoryRouter>
);
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto lo estoy repitiendo en los tests de Home y AuthorDetail, sin embargo, lo hice así para simplificar la cápsula.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant