Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create dynamic fixtures for ember integration tests using ember-testing (Qunit) via teabag
    text
    copied!<ul> <li>I have setup the rather awesome <strong>teabag</strong> <a href="https://github.com/modeset/teabag" rel="nofollow">https://github.com/modeset/teabag</a> to run integration tests on my ember app.</li> <li>I am following the process that Erik Bryn discussed in his presentation: <a href="http://www.youtube.com/watch?v=nO1hxT9GBTs" rel="nofollow">http://www.youtube.com/watch?v=nO1hxT9GBTs</a> using the code in <a href="https://github.com/ebryn/bloggr-client-rails" rel="nofollow">https://github.com/ebryn/bloggr-client-rails</a> as a template.</li> <li>I switch to the ember fixture adapter for testing.</li> </ul> <p>I have everything working nicely with a static fixture which I define in a fixtures files like this:</p> <pre><code>var user = { id: 1, email: "test@testing.com", firstName: "Han", lastName: "Solo" }; var userArray = []; userArray.push(user); App.User.FIXTURES = userArray; </code></pre> <p>But.... if I want to pull the fixture data in dynamically from my existing Rails seed data. (I rename the file to user_fixture.js.erb) and then do:</p> <pre><code>&lt;% @user = User.find_by_email('test@testing.com') %&gt; var currentUser = &lt;%= UserSerializer.new(@user, :root =&gt; false).to_json %&gt;; var userArray = []; userArray.push(user); App.User.FIXTURES = userArray; </code></pre> <p>My tests fail. I can see that the data is not populating the ember app, but if I do:</p> <pre><code>App.User.Fixtures </code></pre> <p>from the console then I can see that the object exists as expected. I am out of ideas as to why this is the case, anyone have any suggestions?</p> <p>For completeness here is how I am setting up Ember in the tests (The same as Erik Bryn's examples):</p> <pre><code>module("Home Routes:", { setup: function() { Ember.run(App, App.advanceReadiness); }, teardown: function() { App.reset(); } }); </code></pre> <p>and here is the contents of test_helper.js:</p> <pre><code>//= require application //= require_tree . //= require_self document.write('&lt;div id="ember-testing-container"&gt;&lt;div id="ember-testing"&gt;&lt;/div&gt;&lt;/div&gt;'); document.write('&lt;style&gt;#ember-testing-container { position: absolute; background: white; bottom: 45px; left: 45px; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }&lt;/style&gt;'); App.rootElement = '#ember-testing'; App.setupForTesting(); App.injectTestHelpers(); function exists(selector) { return !!find(selector).length; }; </code></pre> <p>Update: I have figured out that one (fingers crossed the only) problem with this is that the Active Model Serializer is creating underscore key names, and Ember is expecting camelized versions. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload