This is a basic worked example of how you can test angular applications that doesn't require a browser, just through a console.
Installation and configuration
C:\temp> npm install
C:\temp> mkdir spec\support
C:\temp> echo {} > spec\support\jasmine.json
Usage:
C:\temp> node_modules\.bin\jasmine testsuite.js
C:\temp> node_modules\.bin\jasmine test-http.js
Expected output:
Started
....
4 specs, 0 failures
Finished in 0.028 seconds
npm install reads package.json and installs
angular, angular-mocks, jsdom and jasmine.
test-helper.js loads jsdom and sets some global
variables necessary to simulate a web browser.
app.js is the angular application that we wish to
test.
Injecting controllers is a bit of a pain because the
angular.mock.inject function is not aware of controller
registrations. Instead, a factory function inconveniently
named $controller has to be used to construct a controller.
Luckily we only need to manually inject $scope. The
$controller function will inject other dependencies for us.
See: createController().
Injection of other angular ideas like service, constant, value
in contrast is extremely straightforward. For instance,
angular.mock.inject(_pi_) injects
something that's registered as pi. Alternatively, I noticed that
angular.mock.inject(pi) also works just as well.
You can also mock out existing registrations by getting a
reference to $provide and calling $provide.provider with a
function that returns a new provider. See the example where
I replaced 3.141459 with 42.