Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Last active January 3, 2016 06:59
Show Gist options
  • Save ryanflorence/8426879 to your computer and use it in GitHub Desktop.
Save ryanflorence/8426879 to your computer and use it in GitHub Desktop.
var compile = Ember.Handlebars.compile;
module('Ember.Test Unit Tests', {
setup: function() {
Ember.Test.setupUnitTest();
},
teardown: function() {
Ember.Test.teardownUnitTest();
}
});
test('registerComponent and testComponent', function() {
expect(1);
registerComponent('test', Ember.Component);
testComponent('test').then(function(unit) {
ok(unit instanceof Ember.Component);
});
});
test('registerController and testController', function() {
expect(1);
registerController('test', Ember.Controller);
testController('test').then(function(unit) {
ok(unit instanceof Ember.Controller);
});
});
test('registerRoute and testRoute', function() {
expect(1);
registerRoute('test', Ember.Route);
testRoute('test').then(function(unit) {
ok(unit instanceof Ember.Route);
});
});
test('registerView and testView', function() {
expect(1);
registerView('test', Ember.View);
testView('test').then(function(unit) {
ok(unit instanceof Ember.View);
});
});
test('view: with template', function() {
expect(1);
var View = Ember.View.extend();
// when using views that map to routes you need to specify the templateName
// either in your app or in your test with reopen
View.reopen({ templateName: 'test' });
registerView('test', View);
registerTemplate('test', compile('test'));
testView('test').then(function(test) {
equal($('#qunit-fixture').text().trim(), 'test');
});
});
test('component: with template', function() {
expect(1);
registerComponent('x-test', Ember.Component);
registerTemplate('components/x-test', compile('test'));
testComponent('x-test').then(function(component) {
equal($('#qunit-fixture').text().trim(), 'test');
});
});
test('testSnippet', function() {
expect(2);
registerComponent('x-test', Ember.Component);
registerTemplate('components/x-test', compile('test'));
testSnippet("{{x-test id='☃'}}").then(function(view) {
ok(findView('☃') instanceof Ember.Component);
equal($('#qunit-fixture').text().trim(), 'test');
});
});
test('helpers', function() {
expect(1);
Ember.Handlebars.registerHelper('echo', function(val) {
return val;
});
testSnippet('{{echo "foo"}}').then(function(view) {
equal(view.$().text(), 'foo');
});
});
//test('helper');
//test('template');
//test('testWithTemplate');
@rwjblue
Copy link

rwjblue commented Jan 16, 2014

Related PR's:

  • emberjs/ember.js#4157 - Allows sharing internal logic of Ember.Application.buildContainer.
  • emberjs/ember.js#4159 - Adds Ember.setupForTesting() (which is called when you call App.setupForTesting()). Doesn't do too much yet, but it should be good to build onto.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment