1

controllers/order.js に注文コントローラーがあります

import Ember from 'ember';

export default Ember.Controller.extend({
  needs: "orders"
});

これには /tests/unit/controllers/order-test.js にテストがあります

import { moduleFor, test } from 'ember-qunit';

moduleFor('controller:order', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
});

// Replace this with your real tests.
test('it exists', function(assert) {
var controller = this.subject();
assert.ok(controller);
});

router.js は次のようになります

this.resource('orders', function() {
  this.resource('order', { path: ":order_id"} , function() {
  });
  this.route('create');
});

誰かがテーブル内の注文をクリックすると、テーブルの下に注文の詳細が表示され、ルートがたとえば /orders/1 になる /orders/ ルートがあるという考えです。

単体テストは次のように失敗します。

Died on test #1     at Object.test (http://localhost:4200/assets/test-support.js:1644:11)
at http://localhost:4200/assets/orders-app.js:1464:15
at mod.state (http://localhost:4200/assets/vendor.js:150:29)
at tryFinally (http://localhost:4200/assets/vendor.js:30:14)
at requireModule (http://localhost:4200/assets/vendor.js:148:5)
at Object.TestLoader.require (http://localhost:4200/assets/test-loader.js:29:9)
at Object.TestLoader.loadModules (http://localhost:4200/assets/test-loader.js:21:18): <(subclass of Ember.Controller):ember216> needs [ controller:orders ] but it could not be found

Error: <(subclass of Ember.Controller):ember216> needs [ controller:orders ] but it could not be found
at new Error (native)
at Error.EmberError (http://localhost:4200/assets/vendor.js:22707:21)
at verifyNeedsDependencies (http://localhost:4200/assets/vendor.js:13783:13)
at ControllerMixin.default.reopen.init (http://localhost:4200/assets/vendor.js:13865:11)
at superWrapper [as init] (http://localhost:4200/assets/vendor.js:27980:20)
at new Class (http://localhost:4200/assets/vendor.js:41203:14)
at Function.ClassMixinProps.create (http://localhost:4200/assets/vendor.js:41625:14)
at exports.default.klassy.Klass.extend.defaultSubject (http://localhost:4200/assets/test-support.js:2188:22)
at Object.exports.default.klassy.Klass.extend.contextualizeCallbacks.context.(anonymous function) [as subject] (http://localhost:4200/assets/test-support.js:2209:41)
at Object.<anonymous> (http://localhost:4200/assets/orders-app.js:1465:27)

ここで単体テストに合格するには、セットアップまたはテストで何を変更する必要がありますか?

4

1 に答える 1

1

コントローラーの依存関係をテストに通知する必要があります。これを行うには、moduleFor メソッドを次のように変更します。

moduleFor('controller:order', {
  needs: ['controller:orders']});
于 2015-06-10T12:14:45.313 に答える