A recent update seems to have broken my tests. I'm using Pretender to mock server calls, and I'm getting the error Error: Assertion Failed: The response from a findQuery must be an Array, not undefined
.
Note that I don't get errors when I visit that page in my app. This error only appears when I run the test.
I've already looked at this, this, and this, but none of those solutions seem to apply in my case.
Here's the relevant code in my Pretender helper:
var scores = [
{
id: 1,
name: 'score 1'
}
];
var levels = [
{
id: 1,
name: 'level 1',
score_id: 1
}, {
id: 2,
name: 'level 2',
score_id: 1
}, {
id: 3,
name: 'level 3',
score_id: 1
}
];
return new Pretender(function() {
this.get('api/v1/scores/:id', function(request) {
var score = scores.find(function(score) {
// in the failing test, request.params.id is '1'
if (score.id === parseInt(request.params.id, 10)) {
return score;
}
});
return [200, {"Content-Type": "application/json"}, JSON.stringify({
score: score,
levels: levels
})];
});
});
And this is the test:
test('displays "Project Score"', function() {
visit('/projects/32/scores/1');
andThen(function() {
equal(find('h3.title').text(), 'Project Score');
});
});
Note that this only affects tests using dynamic routes like the one above. Tests that use this route work normally:
this.get('api/v1/scores', function(request) {
return [200, {"Content-Type": "application/json"}, JSON.stringify({
scores: scores
})];
});
I tried bypassing the find
by doing this:
this.get('api/v1/scores/:id', function(request) {
return [200, {"Content-Type": "application/json"}, JSON.stringify({
score: [
{
id: 1,
name: 'score 1'
}
],
levels: levels
})];
});
However, I still get the same error.
Any ideas? How would I debug this issue?
Assorted versions:
Ember CLI: 0.1.12
Node: 0.10.33
NPM: 2.1.8
Ember: 1.10.0
Ember Data: 1.0.0-beta.15
Ember CLI Pretender: 0.3.1
Pretender: 0.6.0
Handlebars: 2.0.0
HTMLBars: ^0.7.4
Ember QUnit: 0.1.8
Ember QUnit Notifications: 0.0.6
QUnit: 1.17.1