Hi,
Just started using Jasmine. With most of the complexity for my current project being in the front-end javascript, it looks to be invaluable. However, I'm struggling with a problem. We're using the revealing module pattern which is based around wrapping code in self-invoking functions.
Pages generally load two scripts. The first is a data access layer and its wrapper passes the breeze library as an argument. The second is the viewModel for the page itself and it passes the data access layer object as an argument.
Everything I want to test is in viewModel. However, in order to run a lot of the functions I need to somehow stop it making calls out to the data layer. Here's a highly simplified explanation of why I'm having problems:
var myClass = function(myArgumentObject) {
var vm = {
myFunction: myFunction,
myVariable: myVariable
}
myFunction() {
myVariable = 1 + 1;
myArgumentObject.aMethod();
}
} (myArgumentObject);How (if at all) can one use the Jasmine framework to spy on (i.e. mock out) myArgumentObject so that one can unit test myFunction?
Doing this:
it('test myFunction', function () {
myClass.myFunction();
expect(myClass.myVariable).toEqual(2);
});Fails because there's an error when it tries to call a method on myArgumentObject. I know I can create a fake version of myArgumentObject with jasmine.createSpy but I can't see how you pass it in.
Cheers,
Matt
--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at http://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/groups/opt_out.