emberjs / data

A lightweight reactive data library for web applications. Designed over composable primitives.
https://api.emberjs.com/ember-data/release
Other
3.04k stars 1.33k forks source link

Intermittent Failures Testing Ember App #821

Closed joefiorini closed 11 years ago

joefiorini commented 11 years ago

I'm having trouble testing my Ember app that uses ember-data to request data.

The only thing slightly unusual that I'm doing is using sinon.js to fake out the Ajax request. Since I can control the response, this allows me to test without model callbacks.

Here are my testing files:

When I run my tests, I'm letting the entire Ember app load into QUnit's fixture. I control the router in my test by transitioning to the state I want to test before running the first test. In between each test I use App.reset() to clear the state of the previous test and reload the route.

The problem is that the second test that runs tries to look up the adapter on the wrong store. When I debug I can see the App.store.toString() returns (for example) "<(subclass of DS.Store):ember747>" but when it get into the store's preprocessData callback, this.toString() returns "<(subclass of DS.Store):ember621>"?

I'm getting quite frustrated by this, and I'm not sure what to look at next. @trek, any ideas what might be going on here?

Thanks!

joefiorini commented 11 years ago

Alright, I think I figured it out. In my setup callback I was assigning the DS.Store after doing an App.reset(). It looks like App.reset() actually triggers the router, causing my route handler to run and look up a DS.Store before the one I created was assigned in the test. Therefore, loading the model used the anonymous store instead of the explicit one. Moving the DS.Store creation before the App.reset() fixed it (surprisingly, since App.reset actually destroys the container?) @wycats @wagenet does this sound right?

Thanks!

CodeOfficer commented 11 years ago

@joefiorini App.reset() actually destroys the app container and calls initialize on the app again which then runs the app injections. Ember Data defines an app injection which will create the default store. So, you should not need to reset the store manually.

https://github.com/emberjs/ember.js/blob/master/packages/ember-application/lib/system/application.js#L433 https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/application_ext.js#L68

joefiorini commented 11 years ago

Except I do not want to use the default store; I have a custom adapter that I need because I'm loading denormalized data.

joefiorini commented 11 years ago

Closing this as my intermittent failures are fixed now. Unfortunatley, there were too many issues to nail it down to a specific cause I can note here.

stefanpenner commented 11 years ago

@joefiorini I would like to see the issues you are having, would you be up to touch base thursday evening, or sometime this weekend?

joefiorini commented 11 years ago

@stefanpenner That would be lovely. I'm past the problems that cause me to open this issue, but I after upgrading to RC2 I got a host of test failures, mostly tying back to em-data. Although I might have it all back by Thursday, I'd love to talk anyway just to see if I'm doing anything crazy and better understand how other people are testing Ember. Up for that? 9pm EST work for you?

kristianmandrup commented 11 years ago

If you wanna do testing in ember with rails, check out my new ember-konacha-rails gem ;) u might find it useful. On Apr 4, 2013 2:19 AM, "Joe Fiorini" notifications@github.com wrote:

@stefanpenner https://github.com/stefanpenner That would be lovely. I'm past the problems that cause me to open this issue, but I after upgrading to RC2 I got a host of test failures, mostly tying back to em-data. Although I might have it all back by Thursday, I'd love to talk anyway just to see if I'm doing anything crazy and better understand how other people are testing Ember. Up for that? 9pm EST work for you?

— Reply to this email directly or view it on GitHubhttps://github.com/emberjs/data/issues/821#issuecomment-15873657 .

stefanpenner commented 11 years ago

@joefiorini yes that works for me. stefan.penner@gmail.com <-- gtalk or something me.