Reputation: 2614
I'm currently using sinonjs with mocha for the test framework. I'm trying to mock out a class, but it doesn't seem to recognize the methods.
Example:
module ModuleA{
export class ClassA {
public funciton1() {
//do something
}
}
}
it.only("test1", function () {
var sandbox = sinon.sandbox.create();
var mockClassA = sandbox.mock(ModuleA.ClassA);
mockClassA.expects("function1").once();
mockClassA.function1();
});
However, It throws an exception
TypeError: Attempted to wrap undefined property function1 as function
I'm new to sinonjs so there is a good chance that I might be using it incorrectly. Function1 is defined in ClassA, so the code is creating a mock for ClassA and then saying that it expects the function1 to be called on the mock. I'm not sure why it can't find function1 as a function.
Any advice appreciated, Thanks, D
Upvotes: 0
Views: 535
Reputation: 37986
mock
method takes instance of the object as a parameter and you're passing a function (class declaration). Use new
keyword to create an instance:
var mockClassA = sandbox.mock(new ModuleA.ClassA());
Upvotes: 1