2017-08-08 2 views
1

私はthis.get('model.property')を利用するコンポーネントを持っており、意図したとおりに動作します。私は、この特定のコンポーネントをテストするときに私は(統合テストが含まれている)すべての私の他のテストのために働いているミラージュを、使用しています私の統合テストのためにEmber.js + Mirage:統合テストで嘲笑された関係を取り戻す

は、しかし、私が取得:

TypeError: Cannot read property 'then' of undefined

これは何です私のテストは、次のようになります。

import { moduleForComponent, test } from 'ember-qunit' 
import hbs from 'htmlbars-inline-precompile' 
import { startMirage } from 'app/initializers/ember-cli-mirage' 
import Ember from 'ember' 

moduleForComponent('summary-card', 'Integration | Component | summary card', { 
    integration: true, 
    beforeEach() { 
    this.server = startMirage() 
    }, 
    afterEach() { 
    this.server.shutdown() 
    } 
}) 

test('it renders', function(assert) { 
    const customer = this.server.create('customer') 
    const location = this.server.create('location', { customer }) 
    const manufacturer = this.server.create('manufacturer') 
    const model = this.server.create('device-model', { manufacturer }) 
    this.server.createList('device', 5, { model, customer, location }) 

    const loc = Ember.Object.create(location) 
    this.set('model', loc) 
    this.render(hbs`{{summary-card model=model model-name=model.name tag='location' belongs-to='customer' has-many='device'}}`); 

    assert.equal(this.$('h1').text().trim(), 'Location 0', 'should be titled Location 0') 

}); 

そして基本的に、私のsummary-card.jsはこのような何かを持っています

this.get('model.' + belongs).then(relationship => {...}) 

belongsは、コンポーネントの呼び出し時にbelongs-toが設定されている値の単純な値です。

模擬モデルのように見えますが、私のテストに合格しているようですが、実行時と同じようにモデルを実際に表現しているわけではありません。ember s(私は開発目的でMirageを使用しています同じように)。そこには正確に何が起こっているのかを知ることができるところがありますか?

ありがとうございました!


P.S.私はまた、server.create()によって提供されるようlocationオブジェクトを使用しようとした、と私は少し異なるエラーを取得する:

TypeError: _this.get(...).then is not a function

答えて

1

まあ、this answerを読み込むことで、私は実際に動作する私の独自のソリューションを、見つけることができましたよく:

import { moduleForComponent, test } from 'ember-qunit' 
import hbs from 'htmlbars-inline-precompile' 
import Ember from 'ember' 

moduleForComponent('summary-card', 'Integration | Component | summary card', { 
    integration: true 
}) 

test('it renders', function(assert) { 
    this.inject.service('store', {as: 'store'}) 
    let location 

    Ember.run(() => { 
    location = this.store.createRecord('location', { 
     id: 0, 
     name: 'Location 0', 
     customer: this.store.createRecord('customer', { 
     id: 1, 
     name: 'Customer 0' 
     }), 
     devices: [this.store.createRecord('device', {id: 1})] 
    }) 
    }) 

    this.set('model', location) 
    this.render(hbs` 
    {{#summary-card model=model model-name=model.name tag='location' belongs-to='customer' has-many='device'}} 
     <div class='test-content'>Test Content</div> 
    {{/summary-card}} 
    `) 

基本的に私はミラージュを使用するのではなく、直接店舗を使用することを選択しました。

関連する問題