Skip to content

Instantly share code, notes, and snippets.

@hmcq6
Last active January 29, 2020 16:27
Show Gist options
  • Save hmcq6/a0f46c4ff2b96041b08f3e806d1a6e02 to your computer and use it in GitHub Desktop.
Save hmcq6/a0f46c4ff2b96041b08f3e806d1a6e02 to your computer and use it in GitHub Desktop.
Hanging Route Test
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
import { set } from '@ember/object';
export default Ember.Controller.extend({
queryParams: ['test', 'type'],
actions: {
changeParam() {
set(this, 'test', '2');
}
}
});
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('route-a');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
async model() {
const { status } = await fetch('https://jsonplaceholder.typicode.com/todos/1', { mode: 'no-cors'});
return status;
},
});
import Ember from 'ember';
import { next } from '@ember/runloop';
import { set } from '@ember/object';
export default Ember.Route.extend({
queryParams: { test: { refreshModel: true }, type: { refreshModel: true } },
async model() {
const rootID = this.modelFor('application');
const { status } = await fetch(`'https://jsonplaceholder.typicode.com/todos/${rootID}`, { mode: 'no-cors' });
return { status };
},
afterModel(model, transition) {
this._super(model, transition);
set(model, 'test', '3');
set(model, 'type', 'other');
1 + 1;
},
setupController(controller, model) {
this._super(controller, model)
next(() => {
this.transitionTo({ queryParams: { test: '1', type: 'none' } });
});
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{#link-to 'route-a'}}Route A{{/link-to}}
{{outlet}}
<br>
<br>
some text
{{model.status}}
<button id="clickMe" {{action "changeParam"}}>this is a button</button>
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
moduleForAcceptance('TODO: put something here');
test('visiting /route-a-hanging', async function(assert) {
await visit('/route-a');
assert.equal(currentURL(), '/route-a?test=1&type=none');
await click('#clickMe');
assert.equal(currentURL(), '/route-a?test=2&type=none');
});
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 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.autoboot = true;
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-qunit';
import { assign } from '@ember/polyfills';
let attributes = assign({ rootElement: '#main' }, config.APP);
setApplication(Application.create(attributes));
start();
{
"version": "0.15.1",
"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.1.4",
"ember-template-compiler": "3.1.4",
"ember-testing": "3.1.4"
},
"addons": {
"ember-data": "3.0.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment