-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
Calling save on models #28
Comments
so interestingly, |
Yes. I've updated the stack trace. It's actually the |
@stefanpenner @rpflorence can someone suggest me in which direction I can start digging, I'd love to help and find a solution for this |
@zigomir https://github.com/rpflorence/ember-qunit/blob/master/lib/module-for-model.js would be a good place to start. |
Thanks. So, if I change return container.lookup('store:main').createRecord(name, options); to return App.__container__.lookup('store:main').createRecord(name, options); it will work for my case. But with this change I break |
@zigomir you do not want to do this, as it defeats the point of isolated tests. We must add all the proper ED serializers to the |
@zigomir I took a look at your tests and it seems more like an integration/acceptance test rather than a controller test. Mostly because calling I suggest you consider making this an acceptance test with appropriate mocked server response. |
@stas Thanks for the response. You're right. This was my question as well. Currently I have a stub API for testing which is much more by definition of integration than unit testing. But I still somehow believe it would be nice if we could mock Currently I'm playing with container.register('serializer:application', DS.JSONSerializer); Now I'm one small step further with this and trying to find a way to properly mock all the things. Now I get But shouldn't Anyhow, if you think this is a blind path for me to pursue, just tell me and will do my testing differently. |
I understand what you are trying to achieve, please let me suggest you try a different approach. Right now you are using the Normally your tests should use as much as possible the same setup as you will be using in production, also because Regarding the stubbed API, this is easily solved by using one of the already suggested ajax mocking libraries. To resume: # app/adapters/application.coffee
Adapter = DS.ActiveModelAdapter.extend
# API End-point namespace
namespace: 'api/v1'
FixtureAdapter = DS.FixtureAdapter.extend()
if window.ENV.development
Adapter = FixtureAdapter
`export default Adapter` Use integration tests if you need to handle data submission by mocking API requests. Example: # test/acceptance/users_index_test.coffee
App = undefined
module 'Users Page',
setup: ->
App = startApp()
$.mockjax
url: '/api/v1/users'
# Could be 'POST', when you are creating a record
type: 'GET'
responseText:
users: [
{id: 1, name: 'User #1'}
{id: 2, name: 'User #2'}
]
teardown: ->
$.mockjaxClear();
Ember.run App, 'destroy'
test 'index renders available users', ->
visit('/users/index').then ->
equal $('.users-list li').length, 2 Consider loading fixtures, only in development. An example implementation can be found in our broccoli boilerplate. |
@stas thanks! I'll try Testing (especially JS code) is still pretty new ground for me and I'm not well educated about good practices yet. I'm gonna close this issue. Thanks for all your help! |
I'm happily using
moduleForModel
helper. But then to be able to call.save()
on the record it returns you need to attach a "new" store to it like soWhich is a bit ugly and
flight
record already contains its store. If I don't "re-attach" store like this I'll get the error when calling.save
on the recordI tried to fix the problem myself but I lack knowledge and couldn't figure it out just yet. Or am I doing something completely wrong for the kind of testing
ember-qunit
wants to provide?The text was updated successfully, but these errors were encountered: