Testing ember extended core objects in ember-cli
I created an ember-cli app where I needed to extend the default store from ember data. For this, I created a file in app / store.js and just extended the store as such:
export default DS.Store.extend({
findOrCreateRecord: function(type, properties, preload) {
...
}
});
This works great, but when I come to test an initializer that uses this new method, I get the following error:
'undefined' is not a function (evaluating 'store.findOrCreateRecord()')
Is there anything I need for my tests to play well here? The file I'm testing is the initializer 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 defaults to the one that ember-cli generates unchanged NO
source to share
Due to the introduction of ember instance initializers in ember 1.12, the initializer in my question will no longer move forward with ember developments as calling lookup
in a container is deprecated. Also as per @tomdale, my use of deferReadiness / advanceReadiness is a hacky way to ensure synchronization in the initializer and is discouraged. It is recommended that you use the application route to implement this functionality.
This is very well explained on GitHub
Also in later versions of ember data, the store has been moved to a service. So my custom store has to be moved to services
my ember-cli project folder. As such, it now becomes trivial to test using the test suite bundled with ember-cli
source to share