Enables angular in Node.js
jsdom-angularjs will inject angular
into your Node.js environment. Useful for running, in Node.js, tests that are made for browsers.
Requires jsdom.
npm install --save-dev --save-exact jsdom jsdom-angularjs
jsdom-angularjs now requires jsdom v10 or above.
Just invoke it to turn your Node.js environment into a DOM environment.
require('jsdom-angularjs')()
// you can now use the DOM
let controller = angular.module('module').controller('controller')
To clean up after itself, just invoke the function it returns.
var cleanup = require('jsdom-angularjs')()
// do things
cleanup()
In tape, run it before your other tests.
require('jsdom-angularjs')()
test('your tests', (t) => {
/* and so on... */
})
Simple: Use Mocha's --require
option. Add this to the test/mocha.opts
file (create it if it doesn't exist)
-r jsdom-angularjs/register
Advanced: For finer control, you can instead add it via mocha's before
and after
hooks.
before(function () {
this.jsdomAngularJS = require('jsdom-angularjs')()
})
after(function () {
this.jsdomAngularJS()
})
If you prefer to use import
rather than require
, you might want to use jsdom-global/register
instead. Place it on top of your other import calls.
import 'jsdom-angularjs/register'
// ...
jsdom-angularjs © 2019+, Igo Ventura. Released under the [MIT] License.
GitHub @igoventura · Twitter @igoventura