meteor / tutorials

The Meteor tutorials from meteor.com
https://www.meteor.com/tutorials
MIT License
181 stars 103 forks source link

Angular Tutorial Step 11.6 - 11.10 Errors #58

Open jannon opened 8 years ago

jannon commented 8 years ago

On Mac OS X I'm running into the following error when trying to do the tutorial testing steps (11.6 & 11.7) that involve angular mocks

ReferenceError: window is not defined
     at Object.<anonymous> (/Users/theuser/simple-todos/node_modules/angular-mocks/angular-mocks.js:3006:4)
     at Module._compile (module.js:456:26)
     at Object.Module._extensions..js (module.js:474:10)
     at Module.load (module.js:356:32)
     at Function.Module._load (module.js:312:12)
     at Module.require (module.js:364:17)
     at require (module.js:380:17)
     at npmRequire (/private/var/folders/bk/vc02hq9x7_b5sksrdkjj4t240000gn/T/meteor-test-run1c7hepa/.meteor/local/build/programs/server/npm-require.js:121:10)
     at Module.useNode (packages/modules-runtime.js:453:20)
     at fileEvaluate (packages/modules-runtime.js:157:20)

If I comment out the angular-mocks import, I get the following error:

Error: Cannot find module '../todosList'
     at require (packages/modules-runtime.js:95:19)
     at meteorInstall.imports.components.todosList.todosList.tests.js (imports/components/todosList/todosList.tests.js:7:1)
     at fileEvaluate (packages/modules-runtime.js:158:9)
     at require (packages/modules-runtime.js:92:16)
     at /private/var/folders/bk/vc02hq9x7_b5sksrdkjj4t240000gn/T/meteor-test-run1c7hepa/.meteor/local/build/programs/server/app/app.js:210:1
    at /private/var/folders/bk/vc02hq9x7_b5sksrdkjj4t240000gn/T/meteor-test-run1c7hepa/.meteor/local/build/programs/server/boot.js:283:10
     at Array.forEach (native)
     at Function._.each._.forEach (/Users/theuser/.meteor/packages/meteor-tool/.1.3.1.nwdv3u++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
     at /private/var/folders/bk/vc02hq9x7_b5sksrdkjj4t240000gn/T/meteor-test-run1c7hepa/.meteor/local/build/programs/server/boot.js:133:5

And, of course, commenting out the todosList import as well at least lets the testrunner proceed, but the tests error since the component it's testing isn't available.

Don't know enough about meteor/angular/mocha yet to have any idea why this is failing

gladiussdv commented 8 years ago

I have the same issue on windows 10. have you found any solution?

Sprechen commented 7 years ago

@jannon I have the same issue on my mac. Did you find a solution on this problem?

MatthieuG9 commented 7 years ago

Same issue on Ubuntu 16.04, meteor 1.4.3.2, any solution ?

MatthieuG9 commented 7 years ago

I solved my issue by executing the test only on client. If the test running in web-browser there is no problem. angular-mocks is only imported on client side.

Here a example of unit test for a service :

/* eslint-env mocha */
import { Meteor } from 'meteor/meteor';
import 'meteor/practicalmeteor:mocha';

if (Meteor.isClient) {

  import { assert } from 'meteor/practicalmeteor:chai';
  import { sinon } from 'meteor/practicalmeteor:sinon';
  import 'angular-mocks';
  import { myModule } from '/imports/ui/modules/myModule';

  describe('myService', function() {
    var service;

    beforeEach(function() {
      window.module(myModule);
      inject(function(_myService_){
        service = _myService_;
      });
    });

    it('should contain a test array', function() {
      assert.lengthOf(service.testArray,4);
    });
  });
}

Execute the command meteor test --driver-package practicalmeteor:mocha for testing and connect the web-browser to localhost to get the results.