2
votes

I am writing test for my custom DS.RESTAdapter, which uses our own SDK as transporter instead of ajax calls. Now, I want to test the adapters find, findAll, findQuery ... functions which require me to pass an instance of store as a parameter. For example:

findAll: function(store, type, sinceToken){...}

To be able to test this, i need to pass "store" param which is not available in moduleFor in ember-qunit (unlike in moduleForModel where you can access store via this.store within the test instance).

Is there another way to gain access to the current instance of store?

Thanks.

Edit:

I solved this by creating mocks for both, store and type. You can create a store instance by:

var store = DS.Store.create({
    adapter: @subject
})

And a mock for type, just as an ordinary object with required properties for the test.

1
I'm not sure if you can directly using moduleFor, but using just module you should be able to access it from the app instance. You can use App.__container__.lookup('store:main') to get back the instance of the ember-data store. - jakecraige
Yes, but that would require me to create a new App instance, which I wanted to avoid. I solved by creating mocks for both, store and type. Thanks for the comment though. - IBQ
Any chance your code is online somewhere? Looking to achieve the same thing and could save a lot of digging. Much appreciated. - getdave

1 Answers

0
votes

You can mock this method (for instance, using Sinon plugin for QUnit). Another solution for accessing the store (but I'm not sure it will work in your case) which helped me to access store from the global namespace is using setup and teardown methods:

  setup: function () {
    Ember.run(App, App.advanceReadiness);
  },
  teardown: function () {
    App.reset();
  }