2016-08-28 4 views
1

Я пытаюсь проверить свой компонент с помощью Жасмина и Углового макета, но я не знаю, как это сделать.Угловой 1,5 тестовый компонент с жасмином

Это мой компонент

var angular = require('angular'); 
'use strict'; 
module.exports = angular 
    .module('app.login.component.login', []) 
    .component('login', { 
     templateUrl: '/app/js/login/components/login.template.html', 
     controller: LoginController 
    }); 

LoginController.$inject = ['$state', 'Auth', 'messages']; 
function LoginController($state, Auth, messages) { 
    var ctrl = this; 
    ctrl.failMessage = messages.NO_AUTH; 
    ctrl.failResponse = false; 
    ctrl.login = login; 

    function login(user){ 
    ctrl.errors = {}; 
    Auth.login(user) 
     .success(function(result){ 
     $state.go('profile'); 
     }) 
     .error(function(response) { 
     ctrl.failResponse = true; 
    }) 
    }; 
} 

Я пишу этот тест, но его работа dosen't. Пожалуйста, объясните мне, что я делаю неправильно и показать некоторые шаблон, как тест компонент

describe('Component: login', function() { 
    beforeEach(angular.mock.module(require('angular-ui-router'))); 
    beforeEach(angular.mock.module(loginComponent.name)); 

    var scope; 
    beforeEach(inject(function($rootScope, $compile){ 
    scope = $rootScope.$new(); 
    })); 

    var controller; 
    beforeEach(inject(function($componentController, Auth) { 
    ctrl = $componentController('login', { 

     $scope:scope}); 
    })); 

    it('df', function() { 
    expect(ctrl.login).toBeDefined(); 
    }); 
}); 

ответ

1

используется $componentController.

beforeEach(inject(function($rootScope, $componentController){ 
    scope = $rootScope.$new(); 
    controller = $componentController('myComponent', {$scope: scope}); 
})); 
Смежные вопросы