jsdom-angularjs

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.

Install

Requires jsdom.

npm install --save-dev --save-exact jsdom jsdom-angularjs

Note

jsdom-angularjs now requires jsdom v10 or above.

Usage

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()

Tape

In tape, run it before your other tests.

require('jsdom-angularjs')()

test('your tests', (t) => {
  /* and so on... */
})

Mocha

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()
})

ES2015

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'
// ...

Thanks

jsdom-angularjs © 2019+, Igo Ventura. Released under the [MIT] License.

GitHub @igoventura  ·  Twitter @igoventura