fac28 / desk-mooovements

https://desk-mooovements.vercel.app
0 stars 2 forks source link

Feedback: testing #136

Open jackherizsmith opened 10 months ago

jackherizsmith commented 10 months ago

The test suite looks great!

No feedback on the content of the tests, except to say that in time (and in developer life this will be required), you may find it helpful to replace the production values by connecting instead to a test database of the same shape but containing gibberish content. For example, arbitrary tags like "socket", "shower" etc might change, so replacing these with test environment variables that are created and destroyed within the cycle of the test keep your tests independent from changes in production to content (where the content itself isn't important). An example of where content is important is something like "submit" on a submit button, or "Log in", etc (i.e. values that aren't kept in the database).

This is a neat little library for generating random content of different types - https://chancejs.com.


When running yarn test I currently get 33 failing tests and 45 passing - is this expected? I don't have any experience with Playwright but looks like it's not finding elements that it expected to find, but perhaps I'm running them incorrectly? Here is one representative error message I'm getting:

    Error: locator.innerText: Page closed
    =========================== logs ===========================
    waiting for getByTestId('cities').locator('div').nth(1)
    ============================================================

      14 |       .locator('div')
      15 |       .nth(1)
    > 16 |       .innerText();
         |        ^
      17 |     [expectedName, expectedWorkplaces] = inputString.split('\n');
      18 |     await page.getByTestId('cities').locator('div').nth(1).click();
      19 |     await page.getByTestId('city-name').innerText();
JamesESS commented 10 months ago

Thanks for the feedback! I was wondering about a test db but ended up spending loads of time reading about mocking and never did either. Would I do this by just providing different env variables for the testing suite? Tests are not supposed to fail but we spent most of yesterday restructuring the site so I'm not suprised about all the failing tests Definetly intreseted in picking your brains about unit testing/jest with next13/14 if you've got any experience

jackherizsmith commented 10 months ago

My preferred approach with testing is broadly:

Building a proper test suite with test db etc can be quite a lot of work, so I agree with the decision to prioritise other things (i.e. building stuff) - the fact you've got tests at all is really good.

What would you like to know about Jest with Next?