When writing tests, explicitly assert specific conditions and expected values rather than relying on general success/failure checks. This prevents tests from silently passing when they should fail and ensures tests verify exactly what they're intended to verify.
When writing tests, explicitly assert specific conditions and expected values rather than relying on general success/failure checks. This prevents tests from silently passing when they should fail and ensures tests verify exactly what they’re intended to verify.
Three key practices to follow:
axios.get('http://localhost:4444/')
.then(function(res) {
// assertions here
done();
}).catch(done); // This ensures test fails if promise rejects
axios.get('http://localhost:4444/')
.catch(function(error) {
assert.equal(error.code, 'ERR_FR_TOO_MANY_REDIRECTS');
// Test specific error conditions, not just that an error happened
done();
});
// Better: Shows exact expected output expect(buildURL(‘/foo’, {date: date})).toEqual(‘/foo?date=’ + encodeURIComponent(date.toISOString())); ```
Following these practices makes tests more reliable indicators of correct behavior and easier to debug when they fail.
Enter the URL of a public GitHub repository