angularjs-webpack: Error running test

I created a project and built off of this starter, but when I try to run my first test:

import app from './app.module'; // set up the app module.
import './globalservices/someService'; // register the service onto the 'app' module.

describe('someService', () => {

  let service;

  beforeEach(() => {
    angular.mock.module('app');

    angular.mock.inject(_someService_ => {
      service = _someService_;
    });
  });

  it('service should exist.', () => {
    console.log(service);
    return;
  });

});

I get an error like

❯ npm run test

> angular-webpack-workflow@1.0.0 test /Users/trusktr/src/refuel4+sme-onboarding
> karma start

05 05 2016 22:22:53.200:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
05 05 2016 22:22:53.245:INFO [launcher]: Starting browser PhantomJS
05 05 2016 22:22:58.348:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#LzaJexxVlI1wyYJ5AAAA with id 1411457
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  ReferenceError: Can't find variable: Map
  at undefined:14

Perhaps one of the files I imported eventually imports something that use new Map, but, as you can see the error isn’t helpful at all (no idea where this happens). Any thoughts?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

After importing babel-polyfill, I still have the same problem. The callback of angular.mock.inject did not execute. Here is my test file.

import home from '../../src/app/home/';

describe('HomeController', () => {
  let ctrl;

  beforeEach(() => {
    console.log('beforeEach::');
    angular.mock.module(home);
    console.log('injectModule::');

    angular.mock.inject(($controller) => {
      ctrl = $controller('HomeController');
    });    
    console.log('injectHomeController::');
  });

  it('should contain the right title', () => {
    console.log('HomeController::', ctrl);
    expect(1).toBe(1);
  });
});

The error message.

LOG: ‘beforeEach::’ LOG: ‘injectModule::’ LOG: ‘HomeController::’, undefined PhantomJS 2.1.1 (Mac OS X 0.0.0) HomeController should contain the right title FAILED forEach@/Users/aaron/demos/angular-webpack/test/tests.webpack.js:8446:25 <- webpack:///~/angular/angular.js:322:0 loadModules@/Users/aaron/demos/angular-webpack/test/tests.webpack.js:12672:13 <- webpack:///~/angular/angular.js:4548:0 createInjector@/Users/aaron/demos/angular-webpack/test/tests.webpack.js:12594:31 <- webpack:///~/angular/angular.js:4470:0 workFn@/Users/aaron/demos/angular-webpack/test/tests.webpack.js:41951:61 <- webpack:///~/angular-mocks/angular-mocks.js:2954:0 inject@/Users/aaron/demos/angular-webpack/test/tests.webpack.js:41931:47 <- webpack:///~/angular-mocks/angular-mocks.js:2934:0 /Users/aaron/demos/angular-webpack/test/tests.webpack.js:42193:25 <- webpack:///test/home/home.spec.js:11:24 /Users/aaron/demos/angular-webpack/test/tests.webpack.js:12712:54 <- webpack:///~/angular/angular.js:4588:0 PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 1 of 1 (1 FAILED) (0 secs / 0.00PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.051 secs / 0.007 secs)