Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passing a "live" ember data list to a component for integration testing #367

Open
cathalmcguire opened this issue Oct 26, 2018 · 5 comments

Comments

@cathalmcguire
Copy link

cathalmcguire commented Oct 26, 2018

I have a component integration test where I pass through a list of models that I'm initiating with factory guy

const TEMPLATE = hbs`{{my-component someList=someList}}`;

hooks.beforeEach(function() {
  this.set('someList', makeList('list-model', 1));
});

Then in the app code I want to create a record

console.log(this.get('someList.length')); //1
this.get('store').createRecord('list-model', {...})
console.log(this.get('someList.length')); //1

I think the problem is that makeList doesn't return a "live" array and as such isn't accessible via the store

I solved this by doing:

hooks.beforeEach(function() {
  mockFindAll('list-model', 1);
  let store = this.owner.lookup('service:store');
  this.set('someList', store.findAll('listModel'));
});

which works fine and is correct so far as it goes. I was just wondering if there was a more eloquent 'factory-guy' way to achieve the same thing.

Thanks
Cathal

@danielspaniel
Copy link
Collaborator

I have been thinking about your code here @cmcguire79 , and one rule of thumb I have is that if the things are looking strange and complicated then there is something that can be improved, so you have good idea to write me to ask that very question.
Problem for me is that I can not see the context of how that model is being added to the list ( someList ). In other words, I can only see the part where that model is added to the 'someList'. If I could see all the code and everything then I could fix this up for you because your are right ( it does not have to be so ugly ) but without better view of everything I can't help.

@cathalmcguire
Copy link
Author

in the application code it's been taken from the result of store.findAll in the route model() it's then passed as a param to the component

@danielspaniel
Copy link
Collaborator

but how are you adding new model to that list then ? in the component ? can you not tell me more ? your saying the very minimal amount

@cathalmcguire
Copy link
Author

ok sorry I'll try to give you a complete picture of the app code

in a route:

model() {
  return this.store.findAll('list-model');
}

on the hbs that consumes this model I initialise the component:

{{some-component someList=model}}

and then in the component js:

this.get('store').createRecord('list-model', {...})
// someList is updated as expected as the 'live' array is passed through 
// from the route to the component

Does this make it clearer?

@danielspaniel
Copy link
Collaborator

still having this problem? If you are can you make a test repo to show the issue? I was not able to grasp it clearly the last time I looked at it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants