2013-11-14 44 views
4

我最近尝试将qUnit和Chutzpah合并到单元测试我正在编写的打印在脚本中的项目。使用Chutzpah运行Typescript qUnit测试

我有事情在安装,我相信什么是正确的方式和下面的工作的事情:

  • 的打字稿应用! - 我可以运行应用程序
  • 放肆的一个非常早期版本 - 我将它安装在VS2012,它正确地看到的我qUnit演示试验
  • qUnit - 出现安装和放肆的作品,我可以运行一个简单的测试(其中一个不看我的代码)

有了这三个到位我认为我可能会开始写的打字稿应用测试,测试我写的打字稿一个简单的测试:

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: "" 
      })') 

现在,我敢肯定这应该是一个构造函数,而是放肆和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 
} 
} 
+1

你应该只能够做新的节点(....),因为你已经在TreeBurst命名空间。你还导出了你的节点类吗? –

+0

@ N.TaylorMullen是的,我得到了相同的结果,不管它是否完全满足,我也导出了该类,将编辑问题以显示,以防我在那里做了错误的事情。 – dougajmcdonald

回答

0

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

+1

感谢您的回复,我在绝望中添加了.js参考!无济于事。我已经更新了引用来使用一个文件夹,或者甚至是对特定的DMC.TreeBurst.Node.ts文件的引用,但我仍然得到相同的响应。 还有其他地方看吗? – dougajmcdonald

1

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

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 
} 
} 
相关问题