M
M
Maks Burkov2017-04-14 17:37:42
Angular
Maks Burkov, 2017-04-14 17:37:42

How to correctly read this test code in Java Script (Angular)?

I'm a Java programmer starting out learning Angular! I came across a piece of code in the tutorial, 2 points are not clear, I wrote questions as comments in the code so that it is clear what exactly the questions are about, I will be glad for an explanation.

describe('PhoneListController', function() {
  beforeEach(module('phonecatApp')); 
  it('should create a `phones` model with 3 phones', inject(function($controller) {
    var scope = {}; // После создания пустого обьекта , этот обьект мапируется к $scope обьекту при передачи обьекта ? 
    var ctrl = $controller('PhoneListController', {$scope: scope}); 
   // Почему получаю доступ через scope а не $scope к phones ?  
    expect(scope.phones.length).toBe(3); 
  }));
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stepanya, 2017-04-14
@Stepanya

describe('PhoneListController', function() {
  beforeEach(module('phonecatApp')); 
  it('should create a `phones` model with 3 phones', inject(function($controller) {
    // Создаём объект
    var scope = {}; 
    // Создаём объект с $scope который ссылается на наш "scope" и с этим скоупом будет работать контроллер
    var ctrl = $controller('PhoneListController', {$scope: scope}); 
    expect(scope.phones.length).toBe(3); 
  }));
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question