我已经为登录公式编写了一个 ember 测试文件。重定向页面是一个带有时间代码边栏的仪表板。现在,当我测试这个时,我在 60000 毫秒后变成了测试超时。我可以在 ember 测试中排除 Time Ticker 组件吗?
我的测试代码:
import {test} from 'qunit';
import moduleForAcceptance from 'frontend/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | Login', {
integration: true
});
test('visiting /user_session/new', function (assert) {
visit('/user_session/new');
fillIn('input#login-email', 'test@example.de');
fillIn('input#login-password', 'blabla');
click('button.btn-primary');
let done = assert.async();
andThen(() => {
Ember.run.later(null, () => {
assert.equal(currentURL(), '/dashboard', 'redirects to the dashboard');
done();
}, 1000);
});
});
时间计时器组件:
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'time',
date: moment().format('DD.MM.YYYY'),
time: Ember.computed('value', function() {
return moment().format('HH:mm:ss');
}),
didInsertElement: function() {
this.tick();
},
tick: function() {
this.set('nextTick', Ember.run.later(this, function() {
this.notifyPropertyChange('value');
this.tick();
}, 1000));
},
willDestroyElement: function() {
Ember.run.cancel(this.get('nextTick'));
}
});
最佳答案
在服务中包装滴答机制并在您的组件中使用该服务。
在测试期间,模拟该服务并将模拟注入(inject)您的组件。虽然在验收测试中模拟对我来说不是一件好事,但我可以在这种情况下使用模拟方法。
您还可以考虑在您的页面中使用 ember-moment
的实时更新。它提供时间的实时更新。 Here有。
关于testing - 使用 Ember 测试登录测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46601345/