バージョンのブログ投稿によると、ストアをサービスとして使用できるようになりました。ember-data
1.0.0-beta.16
TweetComposerComponent = Ember.Component.extend({
store: Ember.inject.service()
});
qunit
ただし、そのようなコンポーネントで単体テストを行う方法がわかりません。私は次のことを試しました:
moduleForComponent('tweet-composer', {
needs: ['service:store']
});
と:
moduleForComponent('tweet-composer', {
needs: ['store:main']
});
前者を実行するとエラーが発生Attempting to register an unknown factory: 'service:store'
し、後者を実行するとエラーが発生しstore
ますundefined
。
考え?
(私はember-cli
スタイルアプリを書いています)。
アップデート:
ember-test-helpers リポジトリには、これに関する未解決の問題があるようです。
この修正を待っている間、応急処置として機能するヘルパー (coffeescript) を作成しました。
`import TestModuleForComponent from 'ember-test-helpers/test-module-for-component'`
`import { createModule } from 'ember-qunit/qunit-module'`
# This assumes the last argument, the callbacks, is present, although it
# does support the description being an optional argument.
moduleForStoreComponent = ->
args = Array.prototype.slice.call arguments
callbacks = args[args.length-1]
# Wrap the original beforeEach callback in a modified version that
# also sets up the store for the test container.
originalSetup = callbacks.beforeEach
callbacks.beforeEach = ->
DS._setupContainer(@container)
originalSetup.call(@) if originalSetup
callbacks.store = ->
@container.lookup('store:main')
args.unshift TestModuleForComponent
createModule.apply @, args
`export default moduleForStoreComponent`