Skip to main content

Unit Testing Support

The *.unit.test.ts or *.unit.test.js files are used to unit test the TypeScript / JavaScript code that is explicitly added by the user.

If the user enables Enable unit test execution flag while creating the pipeline, it will run the command npm run test:unit which will look for the test:unit script in package.json. For example, in a Domain Service Projects (TypeScript), the package.json has something like this

{
"scripts": {
"test:unit": "./node_modules/.bin/mocha --require ./node_modules/ts-node/register/transpile-only -c --recursive test/*.unit.test.ts"
}
}

If the Enable unit test execution flag in a pipeline is enabled, the pipeline will run the script test:unit and will look for *.unit.test.ts files inside the test folder.

As an example, to test a utility function that is defined in src-impl/util/add.ts:

export function add(a: number, b: number): number {
return a + b;
}

Test file test/add.unit.test.ts:

import { expect } from 'chai';
import { add } from '../src-impl/util/add';

describe('generic test', () => {
it('adds 2 numbers', () => {
expect(add(1, 2)).to.equal(3);
})
})