Skip to content

itenium-be/Frontend-UnitTesting

Repository files navigation

Frontend UnitTesting

Exercises are detailed below or in the Github Discussions

Vitest

This project uses Vitest as the test runner. Vitest provides a Jest-compatible API, so Jest knowledge transfers directly. If you know Jest, you know Vitest.

Debugging

Chrome

cd react-testing
bun run test:debug

Put a debugger; statement in your test and open chrome://inspect or use the Node.js V8 --inspector Manager extension.

See Vitest Debugging for more options.

Visual Studio Code

VS Code Extension

See .vscode/launch.json.

Exercise

  • react-testing/src/date-holidays: Is it time to fix the date-holidays performance issue permanently, TDD style?

Express Exercises

See confac
Tag: jest-start
Entrypoint: /backend/src/controllers/tests/

  • 0-config-templates.test.ts: Mocking the FileSystem (easy)
  • 0-user-verify.test.ts: Mocking the google-auth-library (easy)
  • 1-clients.test.ts: Manual Express Mocking (easy)
  • 2-consultants.test.ts: Switching to mongodb-memory-server from our poor-man fakeDb implementation (medium)
  • 3-projectsMonth.test.ts: Mocking Express with supertest (medium)
  • 4-projectsMonth.test.ts: Bringing it all together (medium)
  • 7-deleteInvoiceController.test.ts: You're on your own now (hard)
  • 8-createInvoiceController.test.ts: A whole bunch of mocking (hard)
  • 9-emailInvoiceController.test.ts: Buffers, merging, lots of fun (hard)

Jest

Facebook's test runner that dominated the 2010s. Vitest is the modern successor with the same API. Understanding Jest helps when working with older codebases.

Jasmine

The OG of JavaScript testing frameworks. Jest and Vitest inherited its describe/it/expect syntax. Still useful for understanding the lineage of modern test runners.

React

There are three ways to test React components:

ReactTestUtils: The most barebone API, the other 2 are built on top of this

react-testing-library:

What we will be using.

Enzyme:

The React team no longer recommends the Enzyme library as their primary choice for React testing.

Wired Elements

This was a really bad idea.
But it looks pretty cool.

The DOM

Angular

Protracter is being deprecated?

  • ReactiveForms testing
  • Component testing
  • Directive testing

https://testing-angular.com/

About

Frontend UnitTesting: Jasmine, Jest, React & Angular

Resources

Stars

Watchers

Forks

Contributors