Which setting to use the Ember Test Assistants?

How do you tune your tests to use the new Ember testing assistants, such as visit or find . I have some difficulties to make it work.

I tried the following:

before creating the namespace: Ember.testing = true

in my specification:

App.setupForTesting()

App.injectTestHelpers()

Then I get a message saying that I will need to wrap any asynchronous code with Ember.run, so I did, but my hardware data (mocking GET requests) is somehow not available, so I can’t set the data for them .

Do you get it?

+2
source share
1 answer

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

+4
source

All Articles