ngmock

How to use ngMock to inject $controller

那年仲夏 提交于 2020-01-06 15:07:16
问题 I'm trying to learn unit testing for Angular using Karma, Jasmine, and ngMock. There are at least 2 places in the Angular docs that show how to write unit tests for a controller, and I just have a couple of questions about how they're doing things. From the Controller docs, section on testing controllers: describe('myController function', function() { describe('myController', function() { var $scope; beforeEach(module('myApp')); beforeEach(inject(function($rootScope, $controller) { $scope =

Ng-mock: $compileProvider doesn't have method 'preAssignBindingsEnabled`

↘锁芯ラ 提交于 2020-01-04 02:27:08
问题 I've been rewriting directives in Angular 1.5.8 to components. I want to write unit tests with '$componentController` just like described here: https://docs.angularjs.org/guide/component. The problem is that I'm getting error at this line: var ctrl = $componentController('componentName', null, bindings); saying: undefined is not a constructor (evaluating 'compileProvider.preAssignBindingsEnabled()') app/lib/angular-mocks/angular-mocks.js:2235:80 So it looks like $compileProvider doesn't have