我很难为angularjs(v1.4.9)应用程序创建适当的单元测试,该应用程序包含javascript文件(带有jasmine测试)和typescript文件(根本没有测试,现在我尝试使用Mocha,但它可以是任何框架).
因此它混合和没有模块的旧angularjs,我决定将所有.ts编译成一个bundle.js文件,因为避免了文件排序问题(当我每个.ts有单个.js文件并将其注入gulp任务时会发生index.html).
我的tsconfig.js:
{
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": false,
"removeComments": false,
"outFile": "./wwwroot/bundle.js",
"sourceMap": true,
"inlineSources": true,
"module": "amd",
"moduleResolution": "node",
"target": "es5",
"sourceRoot": "./wwwroot"
},
"include": [
"wwwroot/app/**/*"
],
"exclude": [
"node_modules/**/*",
"tests/**/*"
]
}
Run Code Online (Sandbox Code Playgroud)
测试类的示例:
///<reference path="../models/paymentCondition.model.ts"/>
///<reference path="../../../../../node_modules/@types/angular/index.d.ts"/>
'use strict';
module PaymentCondition {
export class ConnectedCustomersListController {
name: string;
static $inject = ['paymentCondition'];
constructor(private paymentCondition: PaymentConditionModel) {
this.name = paymentCondition.Name;
this.bindData();
}
bindData() {
// do something
}
}
angular
.module('app.paymentConditions')
.controller('ConnectedCustomersListController', …Run Code Online (Sandbox Code Playgroud)