Assuming you are using RC5 (and not RC6 just because it has a small error)
document.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>'); Ember.testing = true; App.rootElement = '#ember-testing'; App.setupForTesting(); App.injectTestHelpers(); function exists(selector) { return !!find(selector).length; } function stubEndpointForHttpRequest(url, json) { $.mockjax({ url: url, dataType: 'json', responseText: json }); } $.mockjaxSettings.logging = false; $.mockjaxSettings.responseTime = 0;
Then you should write your test like this:
module('integration tests', { setup: function() { App.reset(); App.Person.people = []; }, teardown: function() { $.mockjaxClear(); } }); test('ajax response with 2 people yields table with 2 rows', function() { var json = [{firstName: "x", lastName: "y"}, {firstName: "h", lastName: "z"}]; stubEndpointForHttpRequest('/api/people', json); visit("/").then(function() { var rows = find("table tr").length; equal(rows, 2, rows); }); });
The following is a complete example project showing how to add the helper integrator shown above and some basic integration tests (using karma / qunit / jquery-mockjax)
https://github.com/toranb/ember-testing-example
source share