Node.js Testing
- Mocha is a feature-rich JavaScript test framework running on Node. js and in the browser, making asynchronous testing simple and fun
- Chai is a BDD / TDD assertion library for NodeJS and the browser that can be delightfully paired with any javascript testing framework.
- Jest is an open JavaScript testing library from Facebook. Its slogan is “Delightful JavaScript Testing”
- SuperTest is an HTTP assertions library that allows you to test your Node. js HTTP servers. It is built on top of SuperAgent library, wich is an HTTP client for Node.js. SuperTest is for end-to-end tests.
Unit tests
Mocha and Chai
*.spec.ts example
import { IssueTimeTracking, WorkTimeConfig } from './issueTimeTracking';
import { expect } from 'chai';
import 'mocha';
describe('Issue time tracking', () => {
const workTimeConfig = new WorkTimeConfig(5, 8);
/*beforeEach(() => {
});*/
it('original estimate 432000 sec should be 3 weeks', () => {
let issueTimeTracking = new IssueTimeTracking(432000, 86400 , workTimeConfig);
expect(issueTimeTracking.originalEstimateText).to.be.equal('3 weeks');
});
it('spent time 86400 sec should be 3 days', () => {
let issueTimeTracking = new IssueTimeTracking(432000, 86400 , workTimeConfig);
expect(issueTimeTracking.spentTimeText).to.be.equal('3 days');
});
});