Skip to content

Instantly share code, notes, and snippets.

Created September 1, 2015 14:48
Show Gist options
  • Save anonymous/b03bca679aaf71c12e05 to your computer and use it in GitHub Desktop.
Save anonymous/b03bca679aaf71c12e05 to your computer and use it in GitHub Desktop.
Ember Testing Ember testing approaches // source http://jsbin.com/yurope
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Ember testing approaches">
<meta charset="utf-8">
<title>Ember Testing</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.js"></script>
<script src="http://builds.emberjs.com/tags/v1.10.0/ember-template-compiler.js"></script>
<script src="http://builds.emberjs.com/tags/v1.10.0/ember.debug.js"></script>
<script src="http://builds.emberjs.com/tags/v1.0.0-beta.19.2/ember-data.min.js"></script>
<script src="http://code.jquery.com/qunit/qunit-1.18.0.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.18.0.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js"></script>
<script src="https://raw.githubusercontent.com/jakerella/jquery-mockjax/v2.0.1/dist/jquery.mockjax.js"></script>
<style id="jsbin-css">
/* Put your CSS here */
html, body {
margin: 20px;
}
</style>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div id="app"></div>
<script type="text/x-handlebars">
<h2>Ember.js</h2>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<h3>Index</h3>
{{#link-to 'products'}}Products{{/link-to}}
</script>
<script type="text/x-handlebars" data-template-name="products">
<h3>Products</h3>
<ul>
{{#each model as |item|}}
<li>{{item.name}}</li>
{{/each}}
</ul>
</script>
<script id="jsbin-javascript">
// APP
App = Ember.Application.create({
rootElement: '#app'
});
// App.ApplicationAdapter = DS.FixtureAdapter;
App.ApplicationAdapter = DS.RESTAdapter;
App.Router.map(function() {
this.route('products');
});
App.ProductsRoute = Ember.Route.extend({
model: function() {
return this.get('store').find('product');
}
});
App.Product = DS.Model.extend({
name: DS.attr('string')
});
// APP END
// === T E S T S T U F F ===
// MOCKING
App.Product.reopenClass({
FIXTURES: [
{id: 1, name: 'Apple'},
{id: 2, name: 'Orange'}
]
});
$.mockjax({
url: /.*product.*/i,
responseText: {
product: [
{id: 1, name: 'Apple'},
{id: 2, name: 'Orange'}
]
}
});
// MOCKING END
// TEST SETUP
App.setupForTesting();
App.injectTestHelpers();
// TEST SETUP END
// TESTS
module('Ultimate giga mega test module that should work');
test('Products are displayed', function(){
visit('/products');
andThen(function() {
equal(find('li').length, 2);
});
});
// TESTS END
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<meta name="description" content="Ember testing approaches">
<meta charset="utf-8">
<title>Ember Testing</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.js"><\/script>
<script src="http://builds.emberjs.com/tags/v1.10.0/ember-template-compiler.js"><\/script>
<script src="http://builds.emberjs.com/tags/v1.10.0/ember.debug.js"><\/script>
<script src="http://builds.emberjs.com/tags/v1.0.0-beta.19.2/ember-data.min.js"><\/script>
<script src="http://code.jquery.com/qunit/qunit-1.18.0.js"><\/script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.18.0.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js"><\/script>
<script src="https://raw.githubusercontent.com/jakerella/jquery-mockjax/v2.0.1/dist/jquery.mockjax.js"><\/script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div id="app"></div>
<script type="text/x-handlebars">
<h2>Ember.js</h2>
{{outlet}}
<\/script>
<script type="text/x-handlebars" data-template-name="index">
<h3>Index</h3>
{{#link-to 'products'}}Products{{/link-to}}
<\/script>
<script type="text/x-handlebars" data-template-name="products">
<h3>Products</h3>
<ul>
{{#each model as |item|}}
<li>{{item.name}}</li>
{{/each}}
</ul>
<\/script>
</body>
</html>
</script>
<script id="jsbin-source-css" type="text/css">/* Put your CSS here */
html, body {
margin: 20px;
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">// APP
App = Ember.Application.create({
rootElement: '#app'
});
// App.ApplicationAdapter = DS.FixtureAdapter;
App.ApplicationAdapter = DS.RESTAdapter;
App.Router.map(function() {
this.route('products');
});
App.ProductsRoute = Ember.Route.extend({
model: function() {
return this.get('store').find('product');
}
});
App.Product = DS.Model.extend({
name: DS.attr('string')
});
// APP END
// === T E S T S T U F F ===
// MOCKING
App.Product.reopenClass({
FIXTURES: [
{id: 1, name: 'Apple'},
{id: 2, name: 'Orange'}
]
});
$.mockjax({
url: /.*product.*/i,
responseText: {
product: [
{id: 1, name: 'Apple'},
{id: 2, name: 'Orange'}
]
}
});
// MOCKING END
// TEST SETUP
App.setupForTesting();
App.injectTestHelpers();
// TEST SETUP END
// TESTS
module('Ultimate giga mega test module that should work');
test('Products are displayed', function(){
visit('/products');
andThen(function() {
equal(find('li').length, 2);
});
});
// TESTS END</script></body>
</html>
/* Put your CSS here */
html, body {
margin: 20px;
}
// APP
App = Ember.Application.create({
rootElement: '#app'
});
// App.ApplicationAdapter = DS.FixtureAdapter;
App.ApplicationAdapter = DS.RESTAdapter;
App.Router.map(function() {
this.route('products');
});
App.ProductsRoute = Ember.Route.extend({
model: function() {
return this.get('store').find('product');
}
});
App.Product = DS.Model.extend({
name: DS.attr('string')
});
// APP END
// === T E S T S T U F F ===
// MOCKING
App.Product.reopenClass({
FIXTURES: [
{id: 1, name: 'Apple'},
{id: 2, name: 'Orange'}
]
});
$.mockjax({
url: /.*product.*/i,
responseText: {
product: [
{id: 1, name: 'Apple'},
{id: 2, name: 'Orange'}
]
}
});
// MOCKING END
// TEST SETUP
App.setupForTesting();
App.injectTestHelpers();
// TEST SETUP END
// TESTS
module('Ultimate giga mega test module that should work');
test('Products are displayed', function(){
visit('/products');
andThen(function() {
equal(find('li').length, 2);
});
});
// TESTS END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment