Accessing the store within a component test?

So I’m trying to test a component, which accesses a property on the parent controller, that’s populated from the store.

App.AddressFormComponent = Ember.Component.extend({
    countries: Ember.computed.alias('parentController.countries')
})

My question is how to properly pass countries in, so when the component tries to do this.get(‘countries’).find(), it works?

moduleForComponent('address-form')

test('', function() {
    var component = this.subject({
        countries: this.store.find('country') // (this doesn't work )
    })
})

Or maybe theres a better way to do this?

Here’s what I ended up using…

var store = App.__container__.lookup('store:main');

I am using this one too, even if core team members suggested to note use it.

store = App.__container__.lookup("store:main")

Just make sure, you resolve the promise while accessing records.

store.find("item").then (items) ->
  equal(items.get("content").length, 12)

You could also just write an async helper for that and use andThen

1 Like