Karma + mocha Error with module Angularjs

0

Summary

I'm creating a seed for modular design with AngularJS + Browserify + BabelJS. I'm implementing the unit test part.

Problem

When I call the angular module it returns me the error

  

TypeError: module is not a function       at Context. (test.bundle.js: 10: 5)

This happens for $ controller, $ scope ...

TEST

var assert = chai.assert;
var expect = chai.expect;

describe("BaseController", () => {
  beforeEach(() => {
    module('MyApp');
  });
  it("Test1", () => {
    expect(1).to.equal(1);
  });
});

I'm not using CommonJS at the time of running the tests, it generates a bundler for me from all the tests and plays in the ./dist folder

Code

Branch is test-implement

GitHub: code

The project is open-source tips are very welcome.

To Roll

  • git checkout -b test-implement origin / test-implement
  • git checkout test-implement
  • npm install
  • bower install
  • gulp server-test
asked by anonymous 02.10.2015 / 21:33

1 answer

0

My solution was to change the calling of the module module('MyApp') to angular.mocks.module('MyApp') thus:

var assert = chai.assert;
var expect = chai.expect;

describe("thes base controller", () => {
  var scope, controller;

  beforeEach(angular.mock.module("MyApp")); // modificado aqui.

  beforeEach(inject(($controller, $rootScope) => {
    var scope = $rootScope.$new();
    var ctrl = $controller('BaseController', { $scope:scope });
  }));
  it("Test1", ()  => {
    expect(1).to.equal(1);
  });
});

Reference

Angular.mock.module

    
05.10.2015 / 01:35