You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Thanks everyone for #10732 and especially @linclark for documenting it.
I don't know why anyone would want to run their AngularJS application or library on the server, but running tests headlessly in that context is very convenient.
For anyone interested who wishes to test AngularJS code via NodeJS (say via Mocha or something), you'll need the jsdom module, with some sort of fixture such as this in your spec file(s):
// AngularJS needs document and window globals to runglobal.document=require('jsdom').jsdom('<html><head></head><body></body></html>');global.window=global.document.parentWindow;// because AngularJS' index.js expects angular to be in the global namespace, // we need to fake it a bit.// we make this an object so we can easily extend it with the real angular object belowglobal.angular={};// returns the empty object abovevarangular=require('angular');// extend the local angular object with the contents of global.window.angular, // which is the real angular object.global.window.angular.extend(angular,global.window.angular);
I'd be interested if we could somehow avoid this boilerplate by modifying index.js. Adding jsdom as an npm dependency may not be feasible (angular-mocks might want to do this, however--I'd like to hear opinions on that), but perhaps index.js could detect the presence of global.window and global.document and instead export global.window.angular?