我试图了解ctrl = $ controller('TestingAngularControl',{$ scope:scope})中的{$ scope:scope};是吗

时间:2018-10-23 16:55:26

标签: angularjs unit-testing testing jasmine

 describe('Testing Angular JS Test Suite', function() {

  //before each test, use this module
 beforeEach(module('Testing'));

 describe('Test Controller', function() {
//just think what should the controller do
//used to inject angular components into test
var scope,ctrl;
//creates an isolate scope
scope={};
beforeEach(function(){
  inject(function($controller,$rootScope){
    //$rootScope.$new creates a new instance of $rootScope.Scope that inherits from $rootScope.
    //In other words, it creates a new child scope of $rootScope.
    //new child scope of $rootScope
    //alternative is to use $rootScope itself.
    //Doing so might create a mess since it might be used all over the place

      //assign ctrl to angular controller
      //if an object is placed in the scope then it returns the scope
      //like saying
      /*
      $scope {
        title:''
      }
      put in an object and it gives back the isolate scope
      */
      //passing in an isolate scope, and it returns the scope
      ctrl=$controller('TestingAngularControl',{$scope:scope});
      console.log(ctrl);


  });
});
afterEach(function(){
    //cleanup code goes here
});

it('should initialize the title in the scope', function() {
  //this is from angular-mocks and it include the module we created in our app
  //the value to check with the value to check against
  expect(scope.title).toBeDefined();
  expect(scope.title).toBe('Testing Angular Controller');
   });
 });
 });

这些评论只是我试图弄清楚将其作为对象传入时作用域的作用。我假设该对象传递的是空对象,而angularjs从rootScope返回一个隔离的作用域吗?我只想确保我的理解是正确的。这是angularjs,我知道它已经过时了,但仍然很感兴趣。

0 个答案:

没有答案