There are lightweight fakes in tsUnit. These will be extended when generics are added to TypeScript.

Here is an example of substituting a Real Class with a fake in tsUnit.

{{
class RealClass {
public name = 'Real';
run() {
return false;
}
returnValue(): RealClass {
return this;
}
}

class Fakes {
callSubstituteFunctionOnFake(c: tsUnit.TestContext) {
var fakeObject = new tsUnit.Fake(new RealClass());
fakeObject.addFunction('run', function () { return true; });
var target = <RealClass> fakeObject.create();

var result = target.run();

c.isTrue(result);
}
callSubstitutePropertyOnFake(c: tsUnit.TestContext) {
var fakeObject = new tsUnit.Fake(new RealClass());
fakeObject.addProperty('name', 'Test');
var target = <RealClass> fakeObject.create();

var result = target.name;

c.areIdentical('Test', result);
}
}

Last edited Oct 19, 2012 at 9:54 AM by Sohnee, version 1