Testing with sideloaded data


#1

What is the recommended way to test models that are sideloaded. The only way I’ve found so far is to mock out the adapter’s ajax method, which is done in the rest_adapter_test. This seems to be a little overkill, but might be the only way.


#2

This might be a good target for full-stack integration testing.


#3

I would say the same: don’t bother with trying to unit test your app. I’ve taken the “stub out the ajax method” approach too (using sinon.js fakeServer), however, I don’t test the model directly. Instead, I verify that given a particular response, the controller has the correct data, or the template is rendering the correct data. I do all of this within an integration test that has my app fully loaded (here’s an example).

Good luck!


#4

Thanks for the response guys! So you wouldn’t do unit tests even if the models were rather complex (doing a lot of math, lots of observations, and computer properties)? I guess I’m just concerned about having two potential issues (controllers + models) with integration tests.

@joefiorini thanks for the gist!


#5

I understand. At this point in Ember’s life, I would probably still go ahead and load the whole app, and then test the models individually with stubbed responses via the method I mentioned above. I know it seems like overkill, but it beats spending time digging through framework code to figure out what you need to stub.

It looks like someone else on this list has been able to test their models in isolation (see Testing Ember Apps: how do you do it?). I haven’t tried it myself, but if there’s one thing I’ve learned from doing a lot of testing with Rails, it’s that stubbing out a framework is rarely the answer.


#6

I’ve ended up loading the entire application and then loading the data through the adapter. You can see my blog post about it here.

I’m curious to try out the AJAX response like you did it. I think that might simplify a few things.


#7

If the functions are really encapsulated within the models then unit tests should be fine. However, if you’re doing a lot of stubbing, unit tests don’t seem to be worth it.

My current line of thought is to have unit tests for complex models. Detailed JS-only integration test which use JS-based fixtures. And then full-stack integration tests which actually hit your server for data to provide some sanity checks. I feel like the bulk of the test should be JS-only integration tests.