AngularJS and UI-Router: #39;Error: transition superseded#39; during angularjs unit tests(AngularJS 和 UI-Router:在 angularjs 单元测试期间出现“错误:过渡已被取代)
问题描述
我正在尝试为我的项目创建授权包.我在单元测试期间收到错误转换已被取代",但我无法找到实际位置.
I'm attempting to create an authorization package for a project of mine. I'm getting the error 'transition superseded' during my unit tests, and I can't find out where that would actually be.
单元测试:
import angular from 'angular';
import 'angular-mocks';
import worldManagerApp from '../../src/world-manager-app';
import security from '../../src/security/security';
const {inject, module} = angular.mock;
describe('LoginService', ()=> {
let $httpBackend;
let $rootScope;
let successHandler;
let errorHandler;
let LoginService;
const USER = {username: "TEST", password: "PASSWORD"};
beforeEach(function() {
module(worldManagerApp);
module(security);
});
beforeEach(inject((_$httpBackend_, _LoginService_, _$rootScope_) => {
$httpBackend = _$httpBackend_;
$rootScope = _$rootScope_;
LoginService = _LoginService_;
successHandler = jasmine.createSpy('successHandler');
errorHandler = jasmine.createSpy('errorHandler');
}));
it('should exist', () => {
expect(LoginService).toBeDefined();
});
describe('.login()', () => {
describe('when given a proper username and password', () => {
it('should return the username and success', () => {
$httpBackend.expectPOST('/login').respond(200, {user: USER});
LoginService.login("TEST", "PASSWORD");
$rootScope.$digest();
$httpBackend.flush();
expect($rootScope.currentUser).toEqual("TEST");
});
});
});
});
服务:
export default function LoginService($http){
'ngInject';
let service = {};
service.login = login;
function login(username, password){
$http({
url:'/login',
method: 'POST',
data: {
username: username,
password: password,
},
}).then (function(response) {
response.username;
}).catch(function(response){
});
}
return service;
}
错误:
PhantomJS 1.9.8 (Windows 8 0.0.0) LoginService .login() when given a proper username and password should return the username and success FAILED
Error: transition superseded
at C:/Users/Manifest/AppData/Local/Temp/353229d8bf0abe298e7003bab30c0528.browserify:9387 <- node_modules/angular-mocks/angular-mocks.js:261:0
at processChecks (C:/Users/Manifest/AppData/Local/Temp/353229d8bf0abe298e7003bab30c0528.browserify:33750 <- node_modules/angular/angular.js:16674:0)
at C:/Users/Manifest/AppData/Local/Temp/353229d8bf0abe298e7003bab30c0528.browserify:35048 <- node_modules/angular/angular.js:17972:0
at C:/Users/Manifest/AppData/Local/Temp/353229d8bf0abe298e7003bab30c0528.browserify:34862 <- node_modules/angular/angular.js:17786:0
at C:/Users/Manifest/AppData/Local/Temp/353229d8bf0abe298e7003bab30c0528.browserify:521 <- frontend estsecurityloginService.spec.js:42:15
我认为这是一个 ui-Router 问题,但如果我做错了,我无法弄清楚它应该如何工作.
I assume it's a ui-Router problem, but I can't figure out how it should work if I am doing it wrong.
推荐答案
我在将 angular 从 1.5.9 更新到 1.6.1 后遇到了同样的问题,可以通过更新依赖项来解决它:
I had the same issue after update angular from 1.5.9 to version 1.6.1 and could solved it by update the dependencies with:
npm update angular-ui-router
旧版本 0.3.1 导致错误,更新版本 0.3.2 我的应用程序再次正常工作(现在使用 angular 1.6.1).
The old version 0.3.1 leads to the error, with the updated version 0.3.2 my app works fine again (now with angular 1.6.1).
这篇关于AngularJS 和 UI-Router:在 angularjs 单元测试期间出现“错误:过渡已被取代"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:AngularJS 和 UI-Router:在 angularjs 单元测试期间出现“错误:过渡已被取代"


基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01