Ember: Mocking RecordArray

166 Views Asked by At

For acceptance tests of components that involve peekAll, I've stubbed the store service with the peekAll method that returns an array of Ember.Object, by which I'm able to retrieve the records and display.

But save, set and get methods aren't working, as peekAll in it's original form returns a RecordArray.

How do I return a RecordArray from the store stub?

1

There are 1 best solutions below

0
On

Instead of mocking the store service, it might be preferable to inject it, and then use createRecord to add your test record to the store. Then the peekAll will get a RecordArray as per usual, which will include all of the appropriate methods. Otherwise you end up going down a bit of a rabbithole creating more and more mock functions (for example, you could create save, set and get methods, and add them to your EmberObject, but what about the next function you need...).