使用meteor和jasmine进行测试:Iron路由器路由无法按预期工作
我正在尝试使用velocity/jasmine框架为meteor应用程序编写测试 我的老板想要一个端到端的UI测试,所以我需要为用户界面编写测试 我现在有一个问题,我应该如何测试通过应用程序的正常导航。例如,我测试用户注册程序的想法如下:使用meteor和jasmine进行测试:Iron路由器路由无法按预期工作,meteor,jasmine,iron-router,Meteor,Jasmine,Iron Router,我正在尝试使用velocity/jasmine框架为meteor应用程序编写测试 我的老板想要一个端到端的UI测试,所以我需要为用户界面编写测试 我现在有一个问题,我应该如何测试通过应用程序的正常导航。例如,我测试用户注册程序的想法如下: describe 'Login and Usermanagement System', -> it 'should say the user is logged out when no user is logged in', ->
describe 'Login and Usermanagement System', ->
it 'should say the user is logged out when no user is logged in', ->
# This test Works
expect(Meteor.user()).toBeFalsy()
it 'should show a welcome screen if the user is logged out', ->
currentUrl = Router.current().location.get().href;
routeName = Router.current().route.getName();
# This test Works as the startpage in our app (When you hit /) is always system.welcome as long as you are not logged in.
expect(routeName).toBe("system.welcome")
it 'should show a register screen if the user is logged out and clicked on register', (done) ->
Router.go("/register")
routeName = Router.current().route.getName()
# This test does not work as the Router.go seems to be async.
expect(routeName).toBe("system.register")
describe('My Spec', function () {
beforeEach(function (done) {
Router.go('/myPage');
Tracker.afterFlush(done);
});
beforeEach(waitForRouter);
it('should do something', function () {
// Your test
});
});
我的问题是第三次测试。当一个路由加载后,我需要某种回调来做下一件事。当然,我可以等2秒钟左右,但这会不必要地减慢我的测试速度
是否存在Router.goroute、options、callback之类的东西,或者我如何获得这样的行为
我们正在使用的技术:MeteorJS和Iron路由器用于路由,Velocity测试框架和Jasmine用于测试。您需要使用文档中描述的助手 其中指出: 根据要使用的模式,将此帮助程序保存到tests/jasmine/client/integration/lib/wait_for_router_helper.js或tests/jasmine/client/unit/_wait_for_router_helper.js:
(function (Meteor, Tracker, Router) {
var isRouterReady = false;
var callbacks = [];
window.waitForRouter = function (callback) {
if (isRouterReady) {
callback();
} else {
callbacks.push(callback);
}
};
Router.onAfterAction(function () {
if (!isRouterReady && this.ready()) {
Tracker.afterFlush(function () {
isRouterReady = true;
callbacks.forEach(function (callback) {
callback();
});
callbacks = []
})
}
});
Router.onRerun(function () {
isRouterReady = false;
this.next();
});
Router.onStop(function () {
isRouterReady = false;
if (this.next) {
this.next();
}
});
})(Meteor, Tracker, Router);
然后在测试中使用它,如下所示:
describe 'Login and Usermanagement System', ->
it 'should say the user is logged out when no user is logged in', ->
# This test Works
expect(Meteor.user()).toBeFalsy()
it 'should show a welcome screen if the user is logged out', ->
currentUrl = Router.current().location.get().href;
routeName = Router.current().route.getName();
# This test Works as the startpage in our app (When you hit /) is always system.welcome as long as you are not logged in.
expect(routeName).toBe("system.welcome")
it 'should show a register screen if the user is logged out and clicked on register', (done) ->
Router.go("/register")
routeName = Router.current().route.getName()
# This test does not work as the Router.go seems to be async.
expect(routeName).toBe("system.register")
describe('My Spec', function () {
beforeEach(function (done) {
Router.go('/myPage');
Tracker.afterFlush(done);
});
beforeEach(waitForRouter);
it('should do something', function () {
// Your test
});
});
如何在it块内等待路由器?我需要通过多种途径来测试一些东西,例如,进入登录页面,创建用户,更改密码,然后检查密码是否更改。不确定密码是否已更改,也不确定是否已在我的列表中确定,我还无法做到这一点。您可能必须创建另一个要调用的包装函数。