Junior — Middle
Do you have experience writing unit tests for code?
sobes.tech AI
Answer from AI
Yes, in Node.js, frameworks such as Mocha, Jest, or Jasmine are often used for writing unit tests. Unit tests allow checking individual functions or modules for correctness.
Example of a simple test using Jest:
// sum.js
function sum(a, b) {
return a + b;
}
module.exports = sum;
// sum.test.js
const sum = require('./sum');
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
Running such tests helps quickly identify errors when making changes to the code.