Reputation: 1587
I'm using the pretender lib from Trek with success as long as I don't have any query params.
I've now spent officialiy 4 hours staring at the code below and can't get it to work. I'm defining an url that doesn't seem to get hit. But when i look at the call that has not been caught it is coming back with the exact url that I defined! If anybody can help me out with this one that would be great.
The test code I have:
var server;
module("Check Search Index page", {
setup: function() {
'use strict';
Ember.run(function() {
App.reset();
server = new Pretender(function() {
this.get('/api/v1/holidays.json?display_type=detail&page=1&sort%5Bprice%5D=&sort%5Bname%5D=&sort%5Brating%5D=&filter%5Bduration_min%5D=1&filter%5Bduration_max%5D=32&filter%5Bprice_min%5D=50&filter%5Bprice_max%5D=3800&filter%5Bbus%5D=true&filter%5Bflight%5D=true&filter%5Bself_transportation%5D=true', function (request) {
return [200, {'Content-Type': 'application/json'}, '{"holidays":[{"id":507,"name":"App. Elena"}'];
});
});
server.unhandledRequest = function(verb, path, request) {
console.log("=== BEGIN UNHANDLED REQUEST ===");
console.log('verb: ' + verb);
console.log('path: ' + path);
console.log('request: ' + request);
console.log("=== END UNHANDLED REQUEST ===");
};
});
},
teardown: function() {
'use strict';
server.shutdown();
}
});
test('Search page', function() {
'use strict';
visit('/search/index');
andThen(function() {
ok(find('p:contains("Bepaal uw zoek criteria")').length, 'Search page is showing');
});
});
And the error message I get in the console:
.=== BEGIN UNHANDLED REQUEST ===
verb: GET
path: /api/v1/holidays.json?display_type=detail&page=1&sort%5Bprice%5D=&sort%5Bname%5D=&sort%5Brating%5D=&filter%5Bduration_min%5D=1&filter%5Bduration_max%5D=32&filter%5Bprice_min%5D=50&filter%5Bprice_max%5D=3800&filter%5Bbus%5D=true&filter%5Bflight%5D=true&filter%5Bself_transportation%5D=true
request: [object Object]
=== END UNHANDLED REQUEST ===
Upvotes: 2
Views: 701
Reputation: 1587
You should't define the query params in the request definition. For the code above to work the definition of the end point should be:
server = new Pretender(function() {
this.get('/api/v1/holidays.json?', function (request) {
return [200, {'Content-Type': 'application/json'}, '{"holidays":[{"id":507,"name":"App. Elena"}'];
});
});
Upvotes: 2