-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
mockFindAll fails in route test on Ember 2.11 #273
Comments
can you try this: mockSetup(this.container); |
Thanks for the suggestion. Sadly, it still fails. |
Darn, ok .. that was first try. Does this fail with ember-data 2.10 ? or just 2.11 ? Actually ... can you tell me what version of both you have ember/ember-data |
But first try adding a few things so your test looks like: test('it has a student for its model', function(assert) {
let done = assert.async();
mockFindAll('semester', 2);
let route = this.subject();
Ember.run(function() {
let promise = route.model();
promise.then(function(model) {
// model should be an array of 2 semesters .. right?
// so what are you testing exactly? me confused
assert.equal(model.student.get('constructor.modelName'), 'student');
done();
});
});
}); |
what are you trying to test exactly? what this doing? model.student.get('constructor.modelName') if the routes model is returning 2 semesters .. your model would be an array .. no? |
The model is an RSVP hash. The semesters just happen to be one of the things that the hash is returning. Here's the hook: model() {
return Ember.RSVP.hash({
student: this.store.createRecord('student'),
semesters: this.store.findAll('semester').then((semesters) => semesters.sortBy('date'))
});
}, I reduced the test to this and it still fails. Hopefully, this gets some noise out of the equation. test('it has a student for its model', function(assert) {
mockFindAll('semester', 2);
}); Without the I'll try to test against a version that was previously working and let you know the versions of Ember and Ember Data. |
I tried for the last two hours to get a working test run from some previous commit on my repo. I think the combo of Ember wanting to install stuff globally in npm and npm's sad state of affairs for pinning dependencies in a sane way means that I'm not able to get an answer. Shame on me for not having a CI machine where I could quickly point you at a before and after log. I guess that means that I can't say with confidence that the problem cropped up in the jump to 2.11 since I don't always run the test suite before I commit. |
Ok .. no worries. Here's what you can do import Ember from 'ember';
import { mockFindAll, mockSetup, mockTeardown, manualSetup } from 'ember-data-factory-guy';
import { moduleFor, test } from 'ember-qunit';
moduleFor('route:profiles', 'Unit | Route | profiles', {
integration: true, // do this instead of needs, saves alot of headache
// needs: [
// 'model:profile',
// 'transform:blah' => you forgot this
// ]
beforeEach() {
manualSetup(this.container); // you were doing this, but just making sure this is clear
mockSetup();
},
afterEach() {
mockTeardown();
},
}); I have updated factory guy to now spit out a nice message when you make this same configuration mistake ( forgot to needs the transformer ) .. and it is VERY common. checkout factory guy v2.11.5 to get the friendly error message that will tell you exactly what transform you need to add or just use integration:true in the test and you are back in business 😄 |
I switched my setup to exactly this: moduleFor('route:dashboard/students/new', 'Unit | Route | dashboard/students/new', {
beforeEach() {
manualSetup(this.container);
mockSetup();
},
afterEach() {
mockTeardown();
},
integration: true
// needs: [
// 'model:school',
// 'model:semester',
// 'model:student',
// 'validator:number',
// 'validator:presence'
// ]
}); and it is still failing. Now I'm getting a new error before the TypeError that I previously reported. For completeness, I'll put in both tracebacks as I see them from QUnit runner. Assertion after the final `assert.async` was resolved
Source:
at Assert.ok (http://localhost:7357/assets/test-support.js:1770:11)
at Class.exception (http://localhost:7357/assets/test-support.js:4788:47)
at adapterDispatch (http://localhost:7357/assets/vendor.js:49801:13)
at Object.dispatchError (http://localhost:7357/assets/vendor.js:28168:7)
at onerrorDefault (http://localhost:7357/assets/vendor.js:41736:19)
at Object.trigger (http://localhost:7357/assets/vendor.js:68738:11)
at http://localhost:7357/assets/vendor.js:69638:28
at invoke (http://localhost:7357/assets/vendor.js:10889:14)
TypeError: Cannot read property 'serializer' of null
Expected:
true
Result:
false
Source:
at Class.exception (http://localhost:7357/assets/test-support.js:4788:47)
at adapterDispatch (http://localhost:7357/assets/vendor.js:49801:13)
at Object.dispatchError (http://localhost:7357/assets/vendor.js:28168:7)
at onerrorDefault (http://localhost:7357/assets/vendor.js:41736:19)
at Object.trigger (http://localhost:7357/assets/vendor.js:68738:11)
at http://localhost:7357/assets/vendor.js:69638:28 I'm guessing that the new error is the assertion that you added to the code. I'm not sure if my test is structured incorrectly so that I can't read the proper message or if there is something odd about adding an assert there. Thanks for the super fast turnaround! |
Ok @mblayman .. I going to have to get my scuba gear and dive into that code of yours. I can screen share with you and see what is going on, or maybe as a start, show the ENTIRE test ( and not just the top part ) |
@danielspaniel thanks for the generous offer of your time. I found the mistake that I made. Earlier you suggested I add I don't think I understand why adding a |
No problem mate, I enjoy the scuba so I happy to give that code a look around. |
Awesome. Thanks for the explanation. |
Hey, first, thanks for this project! Coming from a Django world, I much prefer using factories over dealing with fixtures.
I upgraded my app to Ember 2.11 and I hit a snag with one of my tests using
mockFindAll
(running [email protected]). The test is a little weird because I'm trying to test a model hook in a route so I'm usingmockFindAll
in a non-acceptance test location. The approach I took was to usemockSetup
andmockTeardown
. Here's the snippet of test code:This test used to work. Now it seems to blow up at the
mockFindAll
line at the start of the test. Here's the traceback I got:I'm not super experienced at deep debugging of Ember tests (dealing with a giant vendor file makes me want to tear my hair out), but I'm happy to provide any additional information that might be helpful.
The text was updated successfully, but these errors were encountered: