I have a complex javascript class that has many functions, many of which will throw exceptions if they are called outside the production environment. I need to pass the mock instances of this class to the constructor of another class in my tests, however I do not want any of the functions of complex classes to actually be called. What I would like to do is to have a fake object that has all the functions and properties of a complex class, but for all functions just to be jasmine spies that do nothing.
Mostly I want to be able to do
var fakeComplexClass = createFakeObject(ComplexClass); var testInstanceOfSimpleClass = new SimpleClass( fakeComplexClass);
And make sure that if testInstanceOfSimpleClass calls any of the fakeComplexClass functions, they will be spies and thus will not break my tests.
I could do something like
var fakeComplexClass = { function1() {};, function2() {}; ... }
but there are many functions, and I have several different complex classes that I need to test, so the simple way to basically track every single function in the class is what I need. \
Jasmine has createSpyObj, but requires you to pass an array of functions to it. I don't want to support this array in my tests if I manage to add or remove functions from a complex class, so I need something that can just spy on every function that is.
Thanks in advance.
source share