$scopeProvider <- $scope/ Unknown provider

后端 未结 3 583
执笔经年
执笔经年 2021-02-05 10:02

I testing my angular-application with jasmine(http://jasmine.github.io/2.0/) and getting next error: Unknown provider: $scopeProvider <- $scope I know, that it\'s incorrect

3条回答
  •  面向向阳花
    2021-02-05 10:28

    I am following a video tutorial from egghead (link bellow) which suggest this approach:

    describe("hello world", function () {
        var appCtrl;
        beforeEach(module("app"))
        beforeEach(inject(function ($controller) {
            appCtrl = $controller("AppCtrl");
        }))
    
        describe("AppCtrl", function () {
            it("should have a message of hello", function () {
                expect(appCtrl.message).toBe("Hello")
            })
        })
    })
    

    Controller:

    var app = angular.module("app", []);
    
    app.controller("AppCtrl",  function () {
        this.message = "Hello";
    });
    

    I am posting it because in the answer selected we are creating a new scope. This means we cannot test the controller's scope vars, no?

    link to video tutorial (1min) : https://egghead.io/lessons/angularjs-testing-a-controller

提交回复
热议问题