P
P
Peter2016-06-03 17:06:18
Angular
Peter, 2016-06-03 17:06:18

How to test controller with sockets in Angularjs?

The controller receives data via sockets.
Depending on the actions already taken by the user and the data received from the socket, one or another component should be shown in the interface.
In this example, I need to keep track of all the states of $scope.someBlock

angular
  .module('myApp')
  .controller('myApp', myApp);
  
function myApp($scope, socketIo){
  var responseStatus = false;
  
  $scope.buttonOne = true;
  $scope.buttonTwo = false;
  $scope.someBlock = false;
  
  socketIo.on('someEvent', function(response){
    //..какой-то код
    responseStatus = response.status
    newFunction()
  })
  
  newFunction(){
    //..какой-то код
    $scope.someBlock = responseStatus && $scope.buttonOne || $scope.buttonTwo && $scope.buttonOne
  }
}

Конечно же это простой пример , в реально же коде зависимостей значительно больше, но суть остается та же
Как это тестировать unit тестами?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Александр Золотых, 2016-06-03
@zolotykh

Возможно поможет использование www.bradoncode.com/blog/2015/05/27/ngmock-fundamen...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question