Jasmine错误:预期未定义为相等

时间:2017-05-29 02:15:22

标签: angularjs html5 jasmine

我想知道为什么我会收到这个错误。我在我的控制器中的角度应用程序中有一个$ scope.message但是当我把expect(scope.message)放到了Equal(“It Works”)时;我得到这个错误,任何人都可以指出我正确的方向,我做错了什么。当我使用索引文件渲染应用程序时,它正在使用Jasmine和Karma进行单元测试。这是我的代码。

var app = angular.module("MyApp", []);

app.controller("MyController",['$scope', function($scope) {
console.log("Reaching Controller");

  $scope.message="Its Good";

   $scope.customer = {
   name: 'Naomi',
   address: '1600 Amphitheatre'
  };


}])


//normilized name factory function and should return an object
    app.directive('myCustomer', function(){
    return function(scope, elem){ //this for strictly testing 
     directives

    elem.append('<span>This span is appended from directive.</span>');
   };
});

 /*Here is my unit test
 describe("Hello PageCtrl working", function() {
    beforeEach(module('MyApp'));

   describe('Reaching Controller', function(){
       var scope,appCtrl, message;


      beforeEach(inject(function($rootScope, $controller) {
      scope = $rootScope.$new();
      appCtrl = $controller("MyController", {$scope:scope}); 

 })); 

        it("should have a message of Its Good", function () {
         expect(scope.message).toEqual("Its Good");
      });
   });
}); 


Thanks In Advance,
HP

0 个答案:

没有答案