Unknown scope provider angularjs unit test -



Unknown scope provider angularjs unit test -

i tried similar illustration on egghead.io. https://egghead.io/lessons/angularjs-testing-a-controller

so test working, stops working 1 time injected $scope , $rootscope controller.

var myapp = angular.module("formulaviewer", []); myapp.controller("appctrl", function($scope, $rootscope) { this.message = "hello"; })

test file

describe("sup", function() { var appctrl; beforeeach(module("formulaviewer")); beforeeach(inject(function ($controller) { appctrl = $controller("appctrl"); })); describe("appctrl", function() { it("should pass", function () { expect(appctrl.message).tobe("hello"); }); }); });

i tried adding $scope, , $rootscope in beforeeach(inject(function ($controller) part, still didn't work.

this error message:

error: [$injector:unpr] unknown provider: $scopeprovider <- $scope http://errors.angularjs.org/1.2.26/$injector/unpr?p0=%24scopeprovider%20%3c-%20%24scope

below how got working.

if doesn't work in scenario can show non-working test you're injecting $rootscope , getting error message?

describe("sup", function() { var appctrl, $scope; // create var $scope beforeeach(module("formulaviewer")); beforeeach(inject(function ($controller, $rootscope) { // inject $rootscope appctrl = $controller("appctrl"); $scope = $rootscope; // assign injected $rootscope $scope })); describe("appctrl", function() { it("should pass", function () { expect(appctrl.message).tobe("hello"); }); }); });

hope helps.

angularjs unit-testing

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -