Skip to content

Instantly share code, notes, and snippets.

@ggayowsky
Last active August 15, 2018 20:31
Show Gist options
  • Save ggayowsky/bb7f5e84d144023190f196aaa743eaf8 to your computer and use it in GitHub Desktop.
Save ggayowsky/bb7f5e84d144023190f196aaa743eaf8 to your computer and use it in GitHub Desktop.
Testing route transition
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: config.locationType,
rootURL: config.rootURL
});
Router.map(function() {
this.route('passing-route');
this.route('failing-route');
});
export default Router;
import Route from '@ember/routing/route';
import { Promise as EmberPromise } from 'rsvp';
export default Route.extend({
model() {
return new EmberPromise((resolve) => {
setTimeout(() => {
resolve('Should fail');
}, 1);
});
}
});
import Route from '@ember/routing/route';
import { Promise as EmberPromise } from 'rsvp';
export default Route.extend({
model() {
return EmberPromise.resolve('Should pass');
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{#link-to "passing-route" class="passing-route-link"}}Go to passing route{{/link-to}}
{{#link-to "failing-route" class="failing-route-link"}}Go to failing route{{/link-to}}
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { currentRouteName, visit } from '@ember/test-helpers';
module('acceptance | plans/import', function(hooks) {
setupApplicationTest(hooks);
test('visiting /passing-route', async function(assert) {
await visit('/passing-route');
assert.equal(currentRouteName(), 'passing-route');
});
});
import { run } from '@ember/runloop';
export default function destroyApp(application) {
run(application, 'destroy');
}
import { module } from 'qunit';
import { resolve } from 'rsvp';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
export default function(name, options = {}) {
module(name, {
beforeEach() {
this.application = startApp();
if (options.beforeEach) {
return options.beforeEach.apply(this, arguments);
}
},
afterEach() {
let afterEach = options.afterEach && options.afterEach.apply(this, arguments);
return resolve(afterEach).then(() => destroyApp(this.application));
}
});
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
import { start } from 'ember-cli-qunit';
setResolver(resolver);
start();
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": true
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment