Testing
Unit Testing
Jest
Jest is a popular JavaScript testing framework that provides a simple, intuitive, and powerful way to write tests for your applications. It's particularly well-suited for testing React, Angular, and Node.js projects.
Jest is designed to work out of the box with minimal setup, making it easy to get started with testing.
Snapshot Testing is important feature of Jest, it generates snapshots of your components or data structures, so you don't need to write and update them manualy, which saves a lot of time.
The testing code looks like this:
import { add, subtract } from './my'
describe('Calculator', () => {
it('should add two numbers correctly', () => {
expect(add(2, 3)).toBe(5)
})
it('should subtract two numbers correctly', () => {
expect(subtract(5, 2)).toBe(3)
})
})
bun
bun has test runner built-in, and it's blazing fast!
$ bun test <<<
bun test v1.1.13 (bd6a6051)
my.test.ts:
✓ Calculator > should add two numbers correctly
✓ Calculator > should subtract two numbers correctly [0.06ms]
2 pass
0 fail
2 expect() calls
Ran 2 tests across 1 files. [10.00ms]
E2E UI Test
Cypress
Cypress is a modern end-to-end testing framework designed for web applications. It runs tests directly in the browser, providing a more reliable and intuitive experience compared to traditional testing tools.
The testing code looks like this:
describe('My Application', () => {
it('should have a welcome message', () => {
cy.visit('/welcome')
cy.contains('Welcome to my application').should('be.visible')
})
})