2017-04-25 56 views

回答

0

wait()函數聽起來像你想要的。不確定它是否符合承諾,因爲它沒有提到這部分文檔中的承諾。無論如何,可能都想給它一個鏡頭。

從灰燼文檔(https://guides.emberjs.com/v2.12.0/testing/testing-components/):

import { moduleForComponent, test } from 'ember-qunit'; 
import wait from 'ember-test-helpers/wait'; 
import hbs from 'htmlbars-inline-precompile'; 

moduleForComponent('delayed-typeahead', 'Integration | Component | delayed typeahead', { 
    integration: true 
}); 

const stubResults = [ 
    { name: 'result 1' }, 
    { name: 'result 2' } 
]; 

test('should render results after typing a term', function(assert) { 
    assert.expect(2); 

    this.set('results', []); 
    this.set('fetchResults', (value) => { 
    assert.equal(value, 'test', 'fetch closure action called with search value'); 
    this.set('results', stubResults); 
    }); 

    this.render(hbs`{{delayed-typeahead fetchResults=fetchResults results=results}}`); 
    this.$('input').val('test'); 
    this.$('input').trigger('keyup'); 

    return wait().then(() => { 
    assert.equal(this.$('.result').length, 2, 'two results rendered'); 
    }); 

}); 

編輯:上面的示例是集成測試......不知道這是什麼,你的想法。請注意,還有你可能想要查看的和助手。也許給我們一些關於你心目中的信息?

相關問題