๐งช TDD with Vitest
How to test JavaScript code with Vitest
Use Vitest to create a few basic unit test for the algorithims in the previous lessons.
npm init -y
npm i -D vitest
Update the package.json with a test script.
package.json
"scripts": {
"test": "vitest"
},
Vitest Basic Example
import { expect, test } from 'vitest';
import { cumSum } from './sum';
test('cumulative sum of an array', () => {
expect(cumSum([1, 3, 5, 7])).toBe(16);
expect(cumSum([-2, -4, -8])).toBe(-14);
});