Live data from Hacker News

Jest/Vitest interactive course (runs in the browser)

howtotestfrontend.com

11–15 of 15 posts

Re: Jest/Vitest interactive course (runs in the browser)

#11

I think unit testing FE to be borderline useless and very expensive to maintain. I have seen so many broken products where leads where obsessed with 100% coverage and quality tests I just don't believe the methodology. E2Es are the only tests that tell you whether the product is making money or not with a good approximation. You have to invest in reducing flakiness and their run time, but if my 5 men team maintaining…

I strongly prefer Playwright over frontend unit tests, just doing what the user does against the system in its entirety, jiggle parameters like resolution and locale / timezone to really lock it down. A good Playwright test suite makes a lot of backend e2e and unit tests redundant.

Re: Jest/Vitest interactive course (runs in the browser)

#12
post #5

Jest mocks allow developers to write bad code. Instead of separating concerns with DI, jest mocks overwrite the importing mechanism without any type safety. Also, if you wish to migrate to native node test runner, the mocks lock you into jest. Use proper mocks with ts mockito and it will force you to write better code.

[deleted]

Re: Jest/Vitest interactive course (runs in the browser)

#13
post #5

Jest mocks allow developers to write bad code. Instead of separating concerns with DI, jest mocks overwrite the importing mechanism without any type safety. Also, if you wish to migrate to native node test runner, the mocks lock you into jest. Use proper mocks with ts mockito and it will force you to write better code.

You can get some type safety with jest mocks with jest.mocked

Anyways I mostly agree, it’s very annoying to use mocks in jest even past the code smell. But I also find certain DI codebases to be highly annoying too. Exceptionally verbose for what it actually accomplishes at times.

Re: Jest/Vitest interactive course (runs in the browser)

#15
post #5

Jest mocks allow developers to write bad code. Instead of separating concerns with DI, jest mocks overwrite the importing mechanism without any type safety. Also, if you wish to migrate to native node test runner, the mocks lock you into jest. Use proper mocks with ts mockito and it will force you to write better code.

100%. its a horrible code smell, and AI loves to jest.mock (or vi.mock()). (The most recent blog post on my site covers this as one of the things to look out for in AI generated tests...) in JS (with Jest/Vitest) it is far too easy to call mock()...

> 100%. its a horrible code smell (...)

It's a testing technique used particularly in legacy projects called characterization tests. If you are faced with covering with tests a component you didn't wrote and you don't want to introduce a regression when refactoring it, you just mock existing function calls to assert observable behavior.

In compiled languages such as C++ this is even done with link time stubs.

Calling it code smell conveys the idea you are inexperienced and lack any experience managing test coverage.

Post reply on HN