Testing with Vitest

In earlier challenges we used console.log to assert whether our functions were working properly. This is acceptable in some situations, but quite restrictive. Luckily, lots of people have written lots of tools and modules to make testing a much easier experience.

One of these is a framework called Vitest, which is pretty awesome, and relatively simple compared to other testing libraries.

Here's a basic Vitest test:

test("test some basic js", () => {
expect(2+2 === 4).toBeTruthy()
expect(3*3).toBe(9)
const testArray = ['dave', 'sharon']
testArray.push('flora')
expect(testArray).toEqual(['dave', 'sharon', 'flora'])
})

Resources