Unit testing 使用Chutzpah运行Typescript qUnit测试

Unit testing 使用Chutzpah运行Typescript qUnit测试,unit-testing,visual-studio-2012,typescript,qunit,chutzpah,Unit Testing,Visual Studio 2012,Typescript,Qunit,Chutzpah,我最近尝试将qUnit和Chutzpah结合起来,对一个用typescript编写的项目进行单元测试 我已经按照我认为正确的方式进行了设置,并且以下各项工作正常: typescript应用程序!-我可以运行该应用程序的早期版本 Chutzpah-我在VS2012上安装了它,它正确地看到了我的qUnit演示测试 qUnit-似乎已安装并与Chutzpah一起工作,我可以运行一个简单的测试(不看我的代码) 有了这三个,我假设我可以开始为typescript应用程序编写测试,作为测试,我用type

我最近尝试将qUnit和Chutzpah结合起来,对一个用typescript编写的项目进行单元测试

我已经按照我认为正确的方式进行了设置,并且以下各项工作正常:

  • typescript应用程序!-我可以运行该应用程序的早期版本
  • Chutzpah-我在VS2012上安装了它,它正确地看到了我的qUnit演示测试
  • qUnit-似乎已安装并与Chutzpah一起工作,我可以运行一个简单的测试(不看我的代码)
有了这三个,我假设我可以开始为typescript应用程序编写测试,作为测试,我用typescript编写了一个简单的测试:

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");

});
}
///<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");

});
}
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
}
}
现在我很确定它应该是一个构造函数,但是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
}
}
//
模块DMC.TreeBurst{
导出接口节点选项{
//特定位置
id:编号;
parentId?:编号;
//节点内部构件
标题:字符串;
内容?:字符串;
颜色?:字符串;
}
导出类节点{
公众id:号码;
公共parentId:number=null;
公共标题:字符串;
公共内容:string=null;
公共深度:number=null;
公共颜色:string=null;
构造函数(选项:节点选项){
//不简洁
}
//为简洁起见,删除了一些方法
}
}

向js文件添加引用无效。另外,没有引用reference.ts reference文件夹,这是因为chutzpah的工作方式(不使用--out编译引用的文件)

我能够让您的示例使用以下测试文件和代码文件的定义。我将所有文件放在同一个目录中,但您可以轻松地移动它们并更改路径

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");

});
}
///<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");

});
}
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
}
}

您应该能够创建新节点(..),因为您已经在TreeBurst命名空间中了。你也导出了你的节点类吗?@N.TaylorMullen是的,我得到了相同的结果,无论是否完全合格,我也导出了该类,我将编辑该问题以表明,如果我在那里做了错误的事情。谢谢你的回复,我在绝望中添加了.js引用!无济于事。我已经更新了引用以使用文件夹,甚至是对特定DMC.TreeBurst.Node.ts文件的引用,但仍然得到相同的响应。还有别的地方可以看吗?