我在用茉莉花做一些打字稿的测试。我创建了一些通过模块声明相互组成的类:
module xxx.DeviceData {
export class ConsoleListener extends DataListener {
constructor() {
super("ConsoleListener");
}
addData(data: string) {
console.log(this.title + ": " + data);
}
clear() {
console.clear();
}
}
}我把茉莉花测试用同样的方式组合在一起:
module xxx.DeviceData {
describe('ConsoleListener test', function () {
var consoleListener,
consoleListenerObj;
beforeEach(() => {
consoleListener = jasmine.createSpy("consoleListener");
consoleListenerObj = jasmine.createSpyObj('consoleListenerObj', ['onSuccess', 'onFailure', 'addData', 'clear']);
consoleListenerObj.onSuccess();
consoleListenerObj.onFailure();
consoleListenerObj.addData();
consoleListenerObj.clear();
});
it('test#1 columnDefinition defined', function () {
let consoleListener = new ConsoleListener();
expect(consoleListener).not.toBeNull();
});
it('test#2 call onSuccess', function () {
expect(consoleListenerObj.onSuccess).toHaveBeenCalled();
});
it('test#3 call onFailure', function () {
expect(consoleListenerObj.onFailure).toHaveBeenCalled();
});
it('test#4 call addData', function () {
expect(consoleListenerObj.addData('123'));
});
it('test#5 call clear', function () {
expect(consoleListenerObj.clear());
});
});
}这一切都很完美。当我尝试执行测试时,我会收到这个错误。
Uncaught : Object prototype可能只是一个对象或null:未定义于Script/DeviceData/ConsoleListener.js:5:27
JS的第5行出了点问题,对吧?以下是:
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var xxx;
(function (xxx) {
var DeviceData;
(function (DeviceData) {
var ConsoleListener = (function (_super) {
__extends(ConsoleListener, _super);
function ConsoleListener() {
return _super.call(this, "ConsoleListener") || this;
}
ConsoleListener.prototype.addData = function (data) {
console.log(this.title + ": " + data);
};
ConsoleListener.prototype.clear = function () {
console.clear();
};
return ConsoleListener;
}(DeviceData.DataListener));
DeviceData.ConsoleListener = ConsoleListener;
})(DeviceData = xxx.DeviceData || (xxx.DeviceData = {}));
})(xxx|| (xxx= {}));
//# sourceMappingURL=ConsoleListener.js.map当然,第5行似乎是在谈论对象和原型。
我尝试过不同的方法来让模块之间进行对话,但是这种模块方法是我唯一能够持续工作的方法。业力/茉莉花背景中有什么东西需要在这里传递吗?
这是我的karma.config:
module.exports = function (config) {
config.set({
frameworks: ["jasmine","karma-typescript"],
preprocessors: {
"Scripts/**/*.ts": ["karma-typescript"]
},
files: [
'Scripts/DeviceData/*.ts',
'Scripts/UnitTests/*.spec.ts'
],
exclude: [
'Scripts/**/NodeJSDataSocket.ts'
],
reporters: ["progress", "karma-typescript"],
//reporters: ["dots", "karma-typescript"],
browsers: ["Chrome"],
karmaTypescriptConfig: {
compilerOptions: {
"module": "commonjs",
"sourceMap": true,
"target": "es5"
"moduleResolution": "classic",
"noImplicitAny": false
},
tsconfig: "./tsconfig.json",
},
});
};发布于 2017-10-05 19:54:05
当您从超类继承时,错误看起来来自于extends函数TypeScript注入。
看看代码,我会说当您使用它时,您的DataListener是不可用的:
extends DataListener 它可能不是完全丢失的,否则编译器会警告您--所以在Jasmine运行时它不是包含(即加载),就是没有顺序加载。
把他们整理好希望..。joy!
files: [
'Scripts/DeviceData/DataListener.ts',
'Scripts/DeviceData/ConsoleListener.ts',
'Scripts/UnitTests/*.spec.ts'
],https://stackoverflow.com/questions/46593647
复制相似问题