Currently, I am facing an issue while writing a unit test in Typescript to check a Typescript class. The problem arises when the test is executed as it is unable to recognize the class.
To provide some context, my setup includes Typescript (1.4) with Node Tools for Visual Studio (2013), and the test conveniently shows up in Test Explorer. However, upon running it, I encounter a failure with the error message "Reference Error: ClassC not defined."
The specific class that I am attempting to test looks like this:
class ClassC {
functionF() {
return 42;
}
}
Upon compiling, the resulting Javascript looks like so:
var ClassC = (function () {
function ClassC() {
}
ClassC.prototype.functionF = function () {
return 42;
};
return ClassC;
})();
//# sourceMappingURL=ClassC.js.map
In order to address this issue, I created a test following the template Add -> new Item... -> TypeScript UnitTest file:
/// <reference path="ClassC.ts" />
import assert = require('assert');
export function classCTest() {
var foo: ClassC = new ClassC();
var result: number = foo.functionF();
assert.equal(result, 42);
}
The resulting Javascript from this test script lacks the essential definition for ClassC
, thus causing the aforementioned error. Despite including the reference path, it did not resolve the issue as anticipated.
Therefore, I am seeking guidance on how to ensure that the unit test recognizes the class properly.