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

Multiple calls to handleCreate() don't work #76

Closed
benlieb opened this issue Apr 20, 2015 · 25 comments
Closed

Multiple calls to handleCreate() don't work #76

benlieb opened this issue Apr 20, 2015 · 25 comments

Comments

@benlieb
Copy link

benlieb commented Apr 20, 2015

I have a test file with multiple test() calls. Inside two I have calls to handleCreate(). Each test run individually succeeds, but together they fail since only the first call to handleCreate() "takes" or "sticks".

https://gist.github.com/pixelterra/cd4e6d7ac3e4794bdf58

This is pretty surprising behavior to me. I would assume that only the "last" call to handleCreate() would be "active".

I suppose that I could work around this by using the match() method and tracking which data is used in each call, but this seems unnecssary and could get messy with many calls to handleCreate().

Is this the only option or am I missing something?

@danielspaniel
Copy link
Collaborator

I'll make this a puzzle for you @pixelterra

Check out the sample acceptance test from the docs, and see if you can spot what you forgot to add to your test.

Hints provided if you don't get it in 30 seconds.

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

Ah setup teardown. :) Lemme give that a go...

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

Ooo. that broke everything :(

@danielspaniel
Copy link
Collaborator

Yikes .. really .. hmm .. now I am puzzled.

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

I'm on 0.2.3 btw

@danielspaniel
Copy link
Collaborator

Me too, but let me check that gist again.

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

Error: Assertion Failed: You cannot use the same root element (#ember-testing) multiple times in an Ember.Application
afterEach failed on fields exist and are empty initally: No model was found for 'test'
afterEach failed on registration fails with bad data, and appropriate errors are displayed: No model was found for 'test'
etc...

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

@danielspaniel
Copy link
Collaborator

I think I know the reason.

Get newest version of ember-data-factory-guy ..

First:
remove it from package.json file
then:
npm prune
then:
ember install ember-data-factory-guy

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

I have "ember-data-factory-guy": "1.0.2",
should I have a newer one?

@danielspaniel
Copy link
Collaborator

Yes, 1.0.3

@danielspaniel
Copy link
Collaborator

Hmm .. tricky .. actually 1.0.2 should work ok .. but if you get 1.0.3 .. at least you'll be on the same page as I am, so I can help out easier.

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

hm

@danielspaniel
Copy link
Collaborator

Yeah . I know .. sounds fishy.

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

installing now

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

actually going to standup with my team in a sec...

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

but I have 2 mins

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

actually that seems to have fixed everything

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

is this setup() and teardown() for FG new?

@danielspaniel
Copy link
Collaborator

no .. it's been there ( in that FactoryGuyTestHelper ) .. for ever ..

@benlieb
Copy link
Author

benlieb commented Apr 20, 2015

well for whatever reason, that fixed everything...

@danielspaniel
Copy link
Collaborator

whew .. glad that worked .. I was starting to think my fingernails were getting tasty there for a second.
I know why it worked .. but glad it's sorted out.
Essentially, you have to call $.mockjax.clear() ( to clear the old mockjax handlers )
which is what the teardown method is doing for you.
the setup call is setting up the response time for mockjax to 0 .. so that will speed up your tests ( that use mockjax ) quite alot.

@danielspaniel
Copy link
Collaborator

So, just for fun, try omitting the setup, and you'll see that those last 3 tests run slower

@danielspaniel
Copy link
Collaborator

This discussion actually showed me a bug .. which I fixed, and pushed out a new version 1.0.4.
You might not encounter it, but its safer to upgrade to this version so you don't get surprised.

@danielspaniel
Copy link
Collaborator

Closing this since issue resolved.

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