Karma+mocha Error with module Angularjs

Asked

Viewed 66 times

0

Summary

I am creating a Seed for modular design with Angularjs + Browserify + Babeljs. I am implementing the unit test part.

Problem

When I call the angular module it returns 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 am not using Commonjs at the time of running the tests, it generates a bundler for me of all tests and plays in the folder . /dist;

Code

Branch is test-implement

Github: code

The project is open-source tips are very welcome.

Para Rodar

  • git checkout -b test-implement origin/test-implement
  • git checkout test-implement
  • npm install
  • Bower install
  • Gulp server-test

1 answer

0


My solution was the modification of the module call module('MyApp')for angular.mocks.module('MyApp') being like this:

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.mockmodule.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.