Angular 1.5测试组分含茉莉 [英] Angular 1.5 test component with jasmine
本文介绍了Angular 1.5测试组分含茉莉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用Jasmine和Angular-mock测试我的组件,但我不知道这是怎么回事。
I try test my component with Jasmine and Angular-mock, but I don't know how this do.
这是我的组件
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;
})
};
}
我写这个测试但是他的工作没有用。
请解释我的错误并展示一些模式如何测试组件
I write this test but his dosen't work. Please explain me what I do wrong and show some pattern how test component
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();
});
});
推荐答案
您使用 $ componentController 。
beforeEach(inject(function($rootScope, $componentController){
scope = $rootScope.$new();
controller = $componentController('myComponent', {$scope: scope});
}));
这篇关于Angular 1.5测试组分含茉莉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文