Unit testing the viewmodels and mocking the dependencies
Asked Answered
B

1

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

Brierroot answered 19/8, 2013 at 4:30 Comment(0)
H
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();
Housebroken answered 19/8, 2013 at 22:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.