Skip to content

Commit

Permalink
Improve acceptance tests and Ember syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
villander committed Jul 9, 2017
1 parent 58f21ac commit 6a64716
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
13 changes: 8 additions & 5 deletions tests/acceptance/simple-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from '../helpers/start-app';

const { run } = Ember;

let App;

module('Simple Acceptance Test', {
Expand All @@ -10,16 +12,17 @@ module('Simple Acceptance Test', {
},

afterEach() {
Ember.run(App, 'destroy');
run(App, 'destroy');
}
});

test('value of input', function(assert) {
test('ES6 features work correcly', function(assert) {
visit('/');

andThen(() => {
assert.equal('Test Value', find('#test-input').val());
assert.equal('one', find('#first-value').text());
assert.equal('two', find('#last-value').text());
assert.equal('Test Value', find('#test-input').val(), 'Has arrow functions and template string as ES6 feature');
assert.equal('one', find('#first-value').text(), 'Has generatos as ES6 feature');
assert.equal('two', find('#last-value').text(), 'Has generatos as ES6 feature');
assert.equal('true', find('#proxy-value').text(), 'Has proxies as ES6 feature');
});
});
21 changes: 19 additions & 2 deletions tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import Ember from 'ember';

export default Ember.Controller.extend({
const { Controller, A, computed } = Ember;

export default Controller.extend({

// Just a very roundabout way of using some ES6 features
value: ((test = 'Test') => `${test} ${'Value'}`)(), // jshint ignore:line

// Test a generator (needs the regenerator runtime) and some ES6 constructs (requires the corejs polyfill)
values: Ember.A(Array.from({ *[Symbol.iterator]() { yield 'one'; yield 'two'; } })) // jshint ignore:line
values: A(Array.from({ *[Symbol.iterator]() { yield 'one'; yield 'two'; } })), // jshint ignore:line

hasProxies: computed({
get() {
const target = {};
const handler = {
get: (receiver, name) => {
return `Hello, ${name}!`;
}
};

const p = new Proxy(target, handler);
return p.world === 'Hello, world!';
}
})
});
6 changes: 4 additions & 2 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import Ember from 'ember';
import config from './config/environment';

const Router = Ember.Router.extend({
const { Router } = Ember;

const EmRouter = Router.extend({
location: config.locationType,
rootURL: config.rootURL
});

Router.map(function() {
EmRouter.map(() => {
});

export default Router;
2 changes: 2 additions & 0 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

<div id="first-value">{{values.firstObject}}</div>
<div id="last-value">{{values.lastObject}}</div>
<div id="name-value">{{nameValue}}</div>
<div id="proxy-value">{{hasProxies}}</div>

{{outlet}}
4 changes: 3 additions & 1 deletion tests/helpers/destroy-app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Ember from 'ember';

const { run } = Ember;

export default function destroyApp(application) {
Ember.run(application, 'destroy');
run(application, 'destroy');
}
8 changes: 5 additions & 3 deletions tests/helpers/start-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';

const { merge, run } = Ember;

export default function startApp(attrs) {
let attributes = Ember.merge({}, config.APP);
attributes = Ember.merge(attributes, attrs); // use defaults, but you can override;
let attributes = merge({}, config.APP);
attributes = merge(attributes, attrs); // use defaults, but you can override;

return Ember.run(() => {
return run(() => {
let application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
Expand Down

0 comments on commit 6a64716

Please sign in to comment.