最近,我尝试将qUnit和Chutzpah合并到单元测试中,我正在编写一个项目,该项目是用类型记录编写的。
我认为事情是以正确的方式设置的,下面的事情是可行的:
有了这三个测试之后,我假设我可以开始为类型记录应用程序编写测试,作为一个测试,我在类型记录中编写了一个简单的测试:
TreeBurst.Tests.ts
///<reference path="../typings/qunit/qunit.d.ts" />
///<reference path="references.ts">
///<reference path="references.js"> // just in case, unsure what needed referencing here
module DMC.TreeBurst {
QUnit.module("TreeBurst.Node.ts tests");
test("Load-a-single-node-creates-correctly", () => {
var node = [new DMC.TreeBurst.Node({
id: 1,
parentId: null,
title: ""
})];
ok(node, "Node not created correctly when provided valid constructor parameters");
});
}不幸的是,当我运行这个程序时,我得到了以下内容:
'undefined' is not a constructor (evaluating 'new DMC.TreeBurst.Node({
id: 1,
parentId: null,
title: ""
})')现在我很确定它应该是一个构造函数,但是Chutzpah和qUnit的组合似乎并没有看到它。
我花了一些时间四处寻找,但我发现的一切都表明事情应该“正常运转”。我是不是做了什么明显的错事?
任何想法都很感激。
编辑:作为对评论的回应,这是类声明:
/// <reference path="references.ts" />
module DMC.TreeBurst {
export interface NodeOptions {
// location specific
id: number;
parentId?: number;
// node internals
title: string;
content?: string;
colour?: string;
}
export class Node {
public id: number;
public parentId: number = null;
public title: string;
public content: string = null;
public depth: number = null;
public colour: string = null;
constructor(opts: NodeOptions) {
//removed from brevity
}
// methods removed for brevity
}
}发布于 2013-12-14 22:10:48
我能够让您的示例为您的测试文件和代码文件使用以下定义。我将所有文件放在同一个目录中,但您可以轻松地移动它们并更改路径。
TreeBurst.tests.ts
///<reference path="qunit.d.ts" />
///<reference path="TreeBurst.ts" />
module DMC.TreeBurst {
QUnit.module("TreeBurst.Node.ts tests");
test("Load-a-single-node-creates-correctly", () => {
var node = [new DMC.TreeBurst.Node({
id: 1,
parentId: null,
title: ""
})];
ok(node, "Node not created correctly when provided valid constructor parameters");
});
}TreeBurst.ts
module DMC.TreeBurst {
export interface NodeOptions {
// location specific
id: number;
parentId?: number;
// node internals
title: string;
content?: string;
colour?: string;
}
export class Node {
public id: number;
public parentId: number = null;
public title: string;
public content: string = null;
public depth: number = null;
public colour: string = null;
constructor(opts: NodeOptions) {
//removed from brevity
}
// methods removed for brevity
}
}发布于 2013-11-14 21:08:41
向js文件添加引用没有任何效果。另外,不是引用reference.ts引用,而是http://matthewmanela.com/blog/chutzpah-2-2-with-typescript-support/文件夹,这是因为chutzpah的工作方式(不编译-out引用的文件)。
https://stackoverflow.com/questions/19986705
复制相似问题