ember.jsember-testingember.js-3

How to access Ember Data store when registering test helper? Ember 3.3


I'm using a custom test helper which requires access to the Ember data store, but I don't know how to access it from the given application argument.

export default registerAsyncHelper('myCustomHelper', function(app) {
  console.log(app); // how to access store?
  let store = app.__registry__.registrations['service:store'];
  store.pushPayload(// json payload);
});

How can I get access to the store when registering a custom helper? I've been trying to figure out a way to access it from the __registry__.registrations['service:store'] key but that gives me an undefined value, when I can see that it's there and has the pushPayload function. Help would be greatly appreciated


Solution

  • Hah! I think I got it:

    export default registerAsyncHelper('myCustomHelper', function(app) {
      let instance = app.buildInstance();
      let store = instance.lookup('service:store');
      store.pushPayload(// json payload);
    });
    

    Not sure if that has any side effects though? Please let me know if it does, I think I've spent enough time trying to setup a good test environment already :p