0

I'm making a simple battleship game.

First, I created the tests for the Board. Now I'm writing the BoardContainer, which holds the state and counts the turns and hits, and renders such Board.

In the Board tests, I check the size of it (10x10), but when testing the container, it will "render" again the Board, so the firsts test fails because now it finds a 20x20 board. Yikes!

I'm not sure what is the proper way to handle this, I don't want to write all the test in the same file because that's not what I would do in a real world project.

here's the codesandbox URL: https://codesandbox.io/s/o75lq4z9n6

Btw, I'm learning TDD so I'm new at this, and I would be really helpful any advice on how to handle this with a production create-react-app project (is it possible it will happen the same?). Thanks in advance!

skyboyer
  • 22,209
  • 7
  • 57
  • 64
diegoalmesp
  • 162
  • 1
  • 13

1 Answers1

2

The problem is that you don't cleanup after each test. https://github.com/kentcdodds/react-testing-library#cleanup

Here's a fixed version: https://codesandbox.io/s/l5okx6zzml

Gio Polvara
  • 23,416
  • 10
  • 66
  • 62