0

Ember Data を使用して、Backbone アプリケーションを Ember アプリケーションに変換する作業を行っています。ブラウザでは問題なく動作しますが、Jasmine のテスト ケースはパスしません。Jasmine テスト ケースでレコードを作成しようとすると、次のエラーが発生します。

TypeError: 'undefined' is not a function (evaluating 'type._create({ store: this })') in http://localhost:8888/spec/javascripts/generated/assets/application.js (line 26874)

これは、エラー メッセージが指す実際のコードです。

createRecord: function(type, properties, transaction) {
    properties = properties || {};

    // Create a new instance of the model `type` and put it
    // into the specified `transaction`. If no transaction is
    // specified, the default transaction will be used.
    //
    // NOTE: A `transaction` is specified when the
    // `transaction.createRecord` API is used.
    var record = type._create({
      store: this // line 26874
    });

テスト ケースが実行している実際のコードは次のようになります。

nutrient = App.Nutrient.createRecord({"name_min":"nut 1","female_31_50_min":7.5,"male_31_50_min":8.0,"created_at":"2011-10-10T01:31:53Z","female_51_70_min":8.5,"updated_at":"2011-10-12T12:28:35Z","male_70_plus_min":10.0,"female_19_30_min":6.5,"child_4_8_min":4.0,"male_19_30_min":7.0,"lactating_14_18_min":5.75,"infant_0_05_min":1.0,"female_70_plus_min":9.5,"pregnant_14_18_min":5.8,"infant_6_12_min":2.0,"id":1,"male_9_13_min":5.0,"child_1_3_min":3.0,"female_9_13_min":4.5,"female_14_18_min":5.5,"male_14_18_min":6.0,"lactating_31_50_min":7.75,"pregnant_31_50_min":7.8,"pregnant_19_30_min":6.8,"male_51_70_min":9.0,"lactating_19_30_min":6.75,"female_31_50_max":8.5,"male_31_50_max":9.0,"female_51_70_max":9.5,"male_70_plus_max":11.0,"female_19_30_max":7.5,"child_4_8_max":5.0,"male_19_30_max":8.0,"lactating_14_18_max":6.75,"infant_0_05_max":2.0,"female_70_plus_max":10.5,"pregnant_14_18_max":6.8,"infant_6_12_max":3.0,"male_9_13_max":6.0,"child_1_3_max":4.0,"female_9_13_max":5.5,"female_14_18_max":6.5,"male_14_18_max":7.0,"lactating_31_50_max":8.75,"pregnant_31_50_max":9.8,"pregnant_19_30_max":7.8,"male_51_70_max":10.0,"lactating_19_30_max":7.75})

person = new App.Person.createRecord({age: 0.25})

expect(nutrient.requiredNutrientForPerson(person)).toEqual({min_amount: 1.0, max_amount: 2.0})

任意のアイデアをいただければ幸いです。

4

2 に答える 2

2

ごめんなさい、私の悪い。問題は次の行にあります。

person = new App.Person.createRecord({age: 0.25})

キーワードを削除する必要がnewあり、正しく機能しました

于 2012-03-30T00:40:52.257 に答える
2

一般に、ブラウザーでは発生しないテストで問題が発生する場合、それはテストが Ember 実行ループの外で実行されているためです。

同期を強制Ember.run.sync()する前に呼び出してみてください。expect()または、バインディングを含むコードを匿名の fn 内に配置しますEmber.run(function() { })

カバレッジはかなりしっかりしているので、他のテスト例については ember と ember-data ソースをチェックしてください。

そうは言っても、私は残り火データの専門家ではないので、これがあなたが経験している問題であるかどうかはわかりません.

于 2012-03-29T18:28:45.640 に答える