首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Chutzpah运行类型记录qUnit测试

使用Chutzpah运行类型记录qUnit测试
EN

Stack Overflow用户
提问于 2013-11-14 19:35:20
回答 2查看 2.3K关注 0票数 4

最近,我尝试将qUnit和Chutzpah合并到单元测试中,我正在编写一个项目,该项目是用类型记录编写的。

我认为事情是以正确的方式设置的,下面的事情是可行的:

  • 打字本应用程序!-我可以运行这个应用程序的早期版本。
  • Chutzpah -我在VS2012上安装了这个,它正确地看到了我的qUnit演示测试
  • qUnit -显示已安装并与Chutzpah一起工作,我可以运行一个简单的测试(一个不看我的代码)

有了这三个测试之后,我假设我可以开始为类型记录应用程序编写测试,作为一个测试,我在类型记录中编写了一个简单的测试:

TreeBurst.Tests.ts

代码语言:javascript
复制
///<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");

});
}

不幸的是,当我运行这个程序时,我得到了以下内容:

代码语言:javascript
复制
'undefined' is not a constructor (evaluating 'new DMC.TreeBurst.Node({
                id: 1,
                parentId: null,
                title: ""
            })')

现在我很确定它应该是一个构造函数,但是Chutzpah和qUnit的组合似乎并没有看到它。

我花了一些时间四处寻找,但我发现的一切都表明事情应该“正常运转”。我是不是做了什么明显的错事?

任何想法都很感激。

编辑:作为对评论的回应,这是类声明:

代码语言:javascript
复制
/// <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
}
}
EN

回答 2

Stack Overflow用户

发布于 2013-12-14 22:10:48

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

TreeBurst.tests.ts

代码语言:javascript
复制
///<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

代码语言:javascript
复制
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
}
}
票数 1
EN

Stack Overflow用户

发布于 2013-11-14 21:08:41

向js文件添加引用没有任何效果。另外,不是引用reference.ts引用,而是http://matthewmanela.com/blog/chutzpah-2-2-with-typescript-support/文件夹,这是因为chutzpah的工作方式(不编译-out引用的文件)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19986705

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档