It looks like you can mock jQuery selector api calls by spying on
$.fn.init. In the case of #ID selectors it works different and
document.getElementById() is used.
I have proof:
When you need to test what is happening inside a constructor it’s not obvious how to do it, because it looks like you can’t spy the SUT when you haven’t even created an instance.
When using Jasmine’s spy.and.callFake, the function execution happens within the spied instance.
This fact is not documented elsewhere but it’s interesting anyway, because it allows some neat tricks.
Some tests to illustrate the scenario:
It may sound obvious but I did it wrong for a while…
When you create a Cordova (Phonegap) application and you want to use npm modules don’t add them within the www folder, use the Cordova project root instead, otherwise the generated node_modules folder will get compiled and added to your build.
The final project structure (as of Cordova 4.0) should look something like this:
| \---package.json // npm project config file
| \---gulpfile.js // Gulp config file
| \---karma.conf.js // Karma test runner config file
The node_modules folder is safe here, it won’t be added to the app build.
The only thing that you have to bear in mind is that configuration files paths have to be prefixed with www.
When you are inspecting the DOM in Chrome Dev-tools there’s a yellowish tooltip that displays information about the currently hovered HTML node.
To get rid of it just press CMD (OSX) or CTRL (WIN) while hovering the Element’s panel in dev-tools.
Happy inspecting :)