6

I'm pretty new in the javascript testing world and I'm having problems implementing some in my hottowel application. Most of the examples that I found online don't go as far as testing amd/require and the ones about amd/require don't show some other stuff.

I'm trying to test my vm by passing a mock service, let's say...

viewModel:

define(['services/dataService'], function (dataService) { function activate() { dataService.returnSomething(); } });

Can someone point me in the right direction (ideally a concrete example) on how to achieve this? Any test framework and mock library is ok.

Thanks

Lucas
  • 63
  • 3

1 Answers1

3

I'm currently using jasmine to unit test my viewmodels.

With Jasmine you have an HTML page that executes all your ViewModels. It allows you to mock out functions. The page I linked to, contains a complete description of what you can do with Jasmine.

Example:

var dataService = Require("services/dataService");
spyOn(dataService , 'returnSomething').andReturn("something");
// execute the system under test here
expect(dataService.returnSomething).toHaveBeenCalled();
Kenneth
  • 28,294
  • 6
  • 61
  • 84