Social networks
You can find me on:
Open sharing content

These articles are available under Creative Commons license BY-SA-3.0

Archive for May, 2014

Lately I have been unit testing a lot of AngularJS scripts and I have started working with concepts like spies and mocks intensively.
If the module you are testing depends on other modules, you might test your controller functions with mocks and spies representing the functions taken from other modules and their services.
But what if your controller function contains a service function that makes an http request?
AngularJs provides Httpbackend to mock http services, but if you provide your own mocks you won´t be able to test the response easily…
Instead of providing a mock you can directly use the module in each test like this:

beforeEach(function () {

Then you can directly use the httpbackend mock.

You might get the following error when running npm or grunt commands:

Error: Cannot find module 'esprima'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\Users\liparulol\git\node_modules\grunt\node_modules\js-yaml\lib\js-yaml\type\js\function.js:4:15
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

A solution might be running “npm clear cache” and then „npm install“. Then you can run the other grunt tasks again.