<html>
<head>
<meta name="description" content="Scaffolding for Ember jsbin tests" />
<meta charset="utf-8">
<title>Ember Tests</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script>
<script src="http://builds.emberjs.com/tags/v1.8.1/ember.js"></script>
<script src='http://code.jquery.com/qunit/qunit-1.14.0.js'></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.14.0.css">
</head>
<body>
<h2>Ember Tests</h2>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div id='ember-testing-container'>
<div id='ember-testing'></div>
</div>
<script type="text/x-handlebars">
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<div class="location-input">
{{input value=searchText}}
</div>
<div class="search-results">
<ul>
{{#each searchResult in model}}
<li>{{searchResult}}</li>
{{/each}}
</ul>
</div>
</script>
</body>
</html>
/* Put your CSS here */
html, body {
margin: 20px;
}
.ember-testing {
position:absolute;
right: 0;
width:400px;
height:400px;
zoom: 50%;
border: 2px solid black;
}
var App = Ember.Application.create({
rootElement: '#ember-testing'
});
App.IndexController = Ember.ArrayController.extend(Ember.PromiseProxyMixin, {
searchText: null, //bound to input field
searchTextChanged: (function() {
var searchText = this.get('searchText');
if (searchText.length === 0) {
this.set('model', []);
return;
}
// simulate an async operation (like hitting a remote API)
// which returns a promise that is ultimately resolved with an
// array of results
var promise = new Ember.RSVP.Promise(function(resolve/*, reject */){
setTimeout(function(){
Ember.run(function(){
resolve([searchText + ", United States"]);
});
}, 500);
});
this.set('promise', promise);
}).observes('searchText')
});
Ember.Test.registerAsyncHelper('waitForControllerWithPromise', function(app, controllerName) {
return new Ember.Test.promise(function(resolve) {
// inform the test framework that there is an async operation in progress,
// so it shouldn't consider the test complete
Ember.Test.adapter.asyncStart();
// get a handle to the promise we want to wait on
var controller = app.__container__.lookup('controller:' + controllerName);
var promise = controller.get('promise');
promise.then(function(){
// wait until the afterRender queue to resolve this promise,
// to give any side effects of the promise resolving a chance to
// occur and settle
Ember.run.schedule('afterRender', null, resolve);
// inform the test framework that this async operation is complete
Ember.Test.adapter.asyncEnd();
});
});
});
var App;
QUnit.test('visiting / and searching', function() {
expect(1);
visit('/');
click('.location-input input');
fillIn('.location-input input', "Los Angeles, CA");
waitForControllerWithPromise('index');
andThen(function(){
var searchResult = find('.search-results ul li:first').text();
equal(searchResult, 'Los Angeles, CA, United States');
});
});
QUnit.testStart(function(){
Ember.run(function(){
App.setupForTesting();
App.injectTestHelpers();
});
});
QUnit.testDone(function(){
Ember.run(App, 'reset');
});
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |