2017-10-06 128 views
0

我已经为登录表单编写了一个ember测试文件。重定向页面是一个带时间标记边栏的仪表板。现在,当我测试这个时,我在60000ms后成为测试时间。我可以排除时间飞行器组件在余烬测试?使用Ember测试登录测试

我的测试代码:

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', '[email protected]'); 
    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')); 
    } 
}); 

回答

0

裹滴答机制和使用该服务在您的组件。

在测试过程中,模拟该服务并在您的组件中注入模拟。虽然嘲笑接受测试对我来说不是一件好事,但我可以在这种情况下采用嘲弄的方法。

你也可以考虑在你的页面中使用ember-moment的实时更新。它提供了实时更新时间。有Here

+0

哦,是的,这是一个好主意。谢谢。 – Daniel