npm i -D chai mocha nyc ts-node typescript
安裝 TypeScript
安裝至專案
npm i -D typescript ts-node安裝至全域
npm i -g typescript建立專案 tsconfig.json
tsc --init安裝 MochaJs
npm i -D mocha @types/mocha安裝 Chai
npm i -D Chai @types/chaipackage.json\
"scripts":{
"test": "mocha -r ts-node/register tests/**/*.test.ts",
}
import { expect } from 'chai';
import Calculator from '../src/calculate';
describe('calculate', function() {
it('add', function() {
let result = Calculator.Sum(5, 2);
expect(result).equal(7);
});
});
export default class calculator {
static Sum(a: number, b: number): number {
}
npm texport default class calculator {
static Sum(a: number, b: number): number {
let c = a + b;
eturn c;
}
calculate
√ add
1 passing (61ms)// TODO
Github 回報有高風險的漏洞,
本機執行 npm i 進行確認
$ npm i
npm WARN marsen.typescript.dojo.datepicker@1.0.0 No repository field.
audited 1517 packages in 3.461s
found 3 vulnerabilities (1 moderate, 2 high)
run `npm audit fix` to fix them, or `npm audit` for details確認有漏洞,執行 npm audit fix 進行自動修複
$ npm audit fix
npm WARN marsen.typescript.dojo.datepicker@1.0.0 No repository field.
+ mocha@6.1.4
added 11 packages from 5 contributors, removed 126 packages, updated 16 packages and moved 4 packages in 9.188s
fixed 2 of 3 vulnerabilities in 1517 scanned packages
1 package update for 1 vuln involved breaking changes
(use `npm audit fix --force` to install breaking changes; or refer to `npm audit` for steps to fix these manually)