1

I am using QUnit to test my typescript code and everything is fine when I run a simple example like this: http://thomasardal.com/testing-typescript-with-typescript-using-qunit-and-chutzpah/

But my nightmare start when I try create unit tests for my SPA app. At the moment to run the testing using Chutzpah on my VS I got a strange error: "Can't Find variable home in mypath\home.tests.ts(line6).

My Code bellow:

home.ts

import logger = module('services/logger');
export var title = 'Home View';

export function activate() {
    logger.log('Home View Activated', null, 'home', true);
    return true;
}

home.tests.ts

/// <reference path="../../Scripts/qunit.d.ts" />
QUnit.module("home.ts tests");
import home = module("home");

test("test title from home viewmodel", function () {

    // Calling to active public function from home viewmodel. (home.ts)   
    var activateResult:string = home.title;

    // Assert
    equal(activateResult, "Home View", "Result should be Home View ");

});

here you are my typeScript settings: setting for typescript

any idea what is wrong with my code?

UPDATE 1 The complete message from output windows in Vs2012 is:

Test 'home.ts tests:test activate function from home viewmodel' failed Died on test #1 at file:///C:/Users/rolando/AppData/Local/Microsoft/VisualStudio/11.0/Extensions/kyo4ap1e.tvo/TestFiles/QUnit/qunit.js:412 at file:///D:/Mercatus/SourceCode/KILN/AquaVet2/SW/AquaVet.Web/App/viewmodels/_Chutzpah.7.home.tests.js:6: Can't find variable: home in D:\Mercatus\SourceCode\KILN\AquaVet2\SW\AquaVet.Web\App\viewmodels\home.tests.ts (line 6)

0 passed, 1 failed, 1 total (chutzpah).

UPDATE 2 As you see in the code i am trying load home.ts using the keyword module("home").... I am not sure if that could be the reason of my problems. A better solution could be add a internal reference to home.ts

Adding home.ts as internal reference

but i don't know how I can reference to activate function !!.

4

1 回答 1

4

仅仅添加一个 import 语句并不包含 AMD 模块——你需要一个诸如require.js 之类的加载器来做到这一点。

一些谷歌搜索会抛出这个https://github.com/jrburke/requirejs/wiki/Test-frameworks,它可以帮助您让 QUnit 使用异步模块。

还有这个关于使用 Chutzpah 和 Require 的讨论,它链接到这个例子

于 2013-05-10T06:08:15.080 回答