Typescript 1.6.2, tsUnit 2.0.1, Node 5.4.1, OSX 10.11.2
I want to unit test functions in my Typescript module using tsUnit. AFAIK, the tsUnit examples only show how to test Typescript classes using Node. The tsUnit Node example shows how to export the target class so it can be required in the unit test. Here's a simplified example:
Foo.ts
class Foo{ ... } export = Foo;
FooTest.ts
import Foo = require('../main/Foo'); var target = new Foo();
I successfully unit tested a Typescript class, but not a module.
I tried two ways to test the module. Both result in Typescript transpile errors.
MyMod.ts
Approach 1: Follow the pattern in the tsUnit class example.
module MyMod {...} export = MyMod; Generates error: Error... TS2339: Property 'MyMod' does not exist on type 'typeof MyMod'.
I don't know what this error means. I couldn't find any applicable solution/explanation via Google or Stackoverflow. Looking at the generated JavaScript code doesn't help me either.
Approach 2: Export the module when it's declared.
export module MyMod {...}
This makes the unit test happier, but in my application code, references to MyMod break. Giving an error like this:
Error... TS2304: Cannot find name 'MyMod'.
How can I make MyMod functions available for unit testing, in a way that doesn't break my application calls to those functions?
[Most likely, I could use a JavaScript test framework for unit tests, but I prefer to use tsUnit if it's possible.]
Aucun commentaire:
Enregistrer un commentaire