I have created an ember-cli application where I needed to extend the default store from ember-data. To do this I have created a file at app/store.js and simply extended the store as such:
export default DS.Store.extend({
findOrCreateRecord: function(type, properties, preload) {
...
}
});
This works great, but when I come to testing an initialiser that makes use of this new method I get the following error:
'undefined' is not a function (evaluating 'store.findOrCreateRecord()')
Is there anything I need to do for my tests to play nicely here? The file that I am testing is the initialiser below:
export function initialize(container, app) {
var store = container.lookup('store:main');
app.deferReadiness();
store.findOrCreateRecord('order', basketToken).then(function(basket) {
container.register('basket:main', basket, { instantiate: false });
app.inject('controller:basket', 'model', 'basket:main');
app.advanceReadiness();
});
}
As for the test file itself, it is the default one that ember-cli generates with NO modifications at all
Due to the introduction of ember instance initializers in ember 1.12 the initializer in my question will no longer work moving forward with ember developments, as calling lookup
on the container is deprecated. Also according to @tomdale my use of deferReadiness/advanceReadiness is a hacky way of providing synchronicity within an initializer and is discouraged. It is suggested that the application route is used instead to implement this functionality.
This is very well explained on GitHub
Also in more recent versions of ember-data the store has been moved into a service. Therefore my custom store has to be moved into the services
folder of my ember-cli project. As such it now becomes trivial to test using the test suite bundled with ember-cli