尝试使用Mocha测试用Typescript编写的类。
该类继承自基类。
由于代码最初是用Typescript(1.7.3)编写的,然后转换为javascript(AMD [requireJs]而不是commonjs)。
所有业务对象都有以下代码片段用于继承:
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
Environnement:
测试是从gulp发起的:
gulp.task("test",function() {
gulp.src(["../test/test-*.js"],{read:false})
.pipe(mocha({
ui:'bdd',
reporter:"spec",
globals:{
should:should
}
}))
});
test.js
describe('Array', function() {
before(function(done) {
var MonetaryAmount= undefined;
require("../PATH/MonetaryAmount", function(ma){
MonetaryAmount = ma;
console.log(ma)
done();
} )
});
describe('Test object creation', function() {
context('Test constructor', function() {
it('should not be undefined', function() {
var newMA = new MonetaryAmount();
newMA.should.not.be.type("undefined");
});
});
});
});
当我运行测试时,我收到以下错误:
$PATH\TO\GULP\FILE>gulp test
[14:50:23] Using gulpfile $PATH\TO\GULP\FILE\gulpfile.js
[14:50:23] Starting 'test'...
[14:50:23] Finished 'test' after 7.76 ms
Array
1) "before all" hook
0 passing (8ms)
1 failing
1) Array "before all" hook:
TypeError: Cannot read property 'prototype' of undefined
at __extends ($\PATH\MonetaryAmount.js:4:72)
Web应用程序在浏览器中工作,但我不确定如何在该上下文中创建测试。