How I define a unit test: An automated test that tests 1 function or...


How I define a unit test: An automated test that tests 1 function or component, alone.

I write unit tests for 2 cases:
1. Reusable, pure util functions (Example: date formatter)
2. Reusable components

Otherwise, I find integration and end-to-end tests generally more valuable.
How I define an integration test: Automating the app in the browser, but mocking all HTTP calls. I write a LOT of these.

How I define an end-to-end test: Automating the app in the browser with nothing mocked. I write a few of these, mostly high-level, just as a "smoke test".
For unit tests, I typically use @jestjs_ or @vitest_dev along with @TestingLib.

For integration and end-to-end tests, I typically use @playwrightweb or @Cypress_io.

For integration test mocking, I use @ApiMocking, and I build custom dev tools to tweak their behavior real-time.
@jestjs_ @vitest_dev @TestingLib @playwrightweb @Cypress_io @ApiMocking If you're curious what I mean by "custom dev tools", here's a demo:

https://switchboard-beta.vercel.app/todos

And here's a repo that shows my general pattern: https://github.com/coryhouse/switchboard

View original on X