Created
November 21, 2013 16:18
-
-
Save FilmKnurd/7584726 to your computer and use it in GitHub Desktop.
Mockjax configuration for Ember App Kit (borrowed from @torunb https://github.com/toranb/ember-testing-example/blob/master/js/tests/integration_test_helper.js)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Install jquery-mockjax into vendor | |
// file: /app/index.html | |
<!-- @if tests=true --> | |
<link rel="stylesheet" href="/vendor/qunit/qunit/qunit.css"> | |
<script src="/vendor/qunit/qunit/qunit.js"></script> | |
<script src="/vendor/jquery-mockjax/jquery.mockjax.js"></script> | |
// And add it to karma.conf | |
// file: karma.conf.js | |
files = [ | |
... | |
'vendor/jquery-mockjax/jquery.mockjax.js', | |
... | |
] | |
// Create helper to stub endpoints | |
// file: /tests/test_helpers.js | |
function stubEndpointForHttpRequest(url, json) { | |
$.mockjax({ | |
url: url, | |
dataType: 'json', | |
responseText: json | |
}); | |
} | |
window.stubEndpointForHttpRequest = stubEndpointForHttpRequest; | |
// Configure mockjax | |
// file: /tests/helpers/start_app.js | |
window.$.mockjaxSettings.logging = false; | |
window.$.mockjaxSettings.responseTime = 0; | |
// Use in tests | |
// file: /tests/acceptance/some_test.js | |
test('some test', function(){ | |
stubEndpointForHttpRequest('/api/some/route/here', {...}); | |
expect(1); | |
visit('/').then(function(){ | |
ok(true); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment