Skip to content

Instantly share code, notes, and snippets.

@blimmer
Created September 20, 2018 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blimmer/f4132e4e885e0fe2e2cc67232e32a56d to your computer and use it in GitHub Desktop.
Save blimmer/f4132e4e885e0fe2e2cc67232e32a56d to your computer and use it in GitHub Desktop.
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['card-thingy'],
click() {
this.sendAction('transitionToMyRoute');
}
});
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: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('my-route');
this.route('my-other-route');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
transitionToMyRoute() {
this.transitionTo('my-route');
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
});
<h1>Click action + link-to different behavior in tests</h1>
<p>I noticed this difference between the actually using the app vs. in test. In this case, I have a button inside a component that goes to a different route than the component itself. We could argue about the UX, but that's another story. If you interact with the real component, clicking the button goes to a different route, but this behavior is different in test.</p>
<br>
<br>
{{outlet}}
<br>
<br>
<div style='height: 200px; width: 200px; cursor: pointer; border: 1px black solid;'>
Click anywhere in this card to go to my-route.
{{#link-to 'my-other-route' tagName='button'}}Click here to go to my-other-route{{/link-to}}
</div>
{{card-thingy transitionToMyRoute='transitionToMyRoute'}}
<h1>On "my-other-route"</h1>
{{#link-to 'index'}} Back {{/link-to}}
<h1>On "my-route"</h1>
{{#link-to 'index'}} Back {{/link-to}}
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
moduleForAcceptance('Behavior');
test('visiting /my-acceptance', function(assert) {
visit('/');
click('.card-thingy');
andThen(function() {
assert.equal(currentURL(), '/my-route');
});
});
test('clicking the button', function(assert) {
visit('/');
click('.card-thingy button');
andThen(function() {
assert.equal(currentURL(), '/my-other-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