Created
July 16, 2014 11:43
-
-
Save suchitpuri/c00fc69f290c01a3541b to your computer and use it in GitHub Desktop.
This file contains 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
/* Put your CSS here */ | |
html, body { | |
margin: 10px; | |
} |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Custom Test Helpers</title> | |
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.14.0.css"> | |
<meta name="description" content="guide: test-helpers-1" /> | |
<meta charset="utf-8"> | |
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.14.0.css"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> | |
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.2.1.js"></script> | |
<script src="http://builds.emberjs.com/release/ember.js"></script> | |
<script src="http://code.jquery.com/qunit/qunit-1.14.0.js"></script> | |
</head> | |
<body> | |
<div id="qunit"></div> | |
<div id="ember-testing"></div> | |
<script type="text/x-handlebars"> | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="index"> | |
<button class='click-me' {{action "addClick"}}>Click Me</button> | |
</script> | |
</body> | |
</html> |
This file contains 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
/*=================== APP ====================*/ | |
App = Ember.Application.create(); | |
App.Router.map(function() {}); | |
App.IndexController = Ember.Controller.extend({ | |
didClick: false, | |
actions: { | |
addClick: function(){ | |
this.set('didClick', true); | |
} | |
} | |
}); | |
// /*=================== TESTS ====================*/ | |
App.setupForTesting(); | |
App.rootElement = '#ember-testing'; | |
// register custom helper | |
Ember.Test.registerHelper('getController', | |
function(app, controllerName) { | |
return app.__container__.lookup('controller:' + controllerName); | |
} | |
); | |
// register custom helper | |
Ember.Test.registerAsyncHelper('visitIndexAndClickButton', | |
function(app) { | |
visit('/'); | |
click('button.click-me'); | |
return wait(); | |
} | |
); | |
// must be called after the helpers are registered | |
App.injectTestHelpers(); | |
module('Custom Test Helpers', { | |
setup: function() { | |
Ember.run(App, App.advanceReadiness); | |
}, | |
teardown: function() { | |
App.reset(); | |
} | |
}); | |
test('test visit / and click button', function() { | |
expect(1); | |
visitIndexAndClickButton(); | |
andThen(function(){ | |
var c = getController('index'); | |
ok(c.get('didClick')); | |
}); | |
}); | |
test('tsdfgand click button', function() { | |
expect(1); | |
visitIndexAndClickButton(); | |
andThen(function(){ | |
var c = getController('index'); | |
ok(c.get('didClick')); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment