Skip to content

Instantly share code, notes, and snippets.

@jelhan
Created October 10, 2018 20:36
Show Gist options
  • Save jelhan/dd417cf8757607cdd669448c42ce7bbc to your computer and use it in GitHub Desktop.
Save jelhan/dd417cf8757607cdd669448c42ce7bbc to your computer and use it in GitHub Desktop.
52694803/cannot-send-an-action-from-the-controller-to-the-route-in-a-unit-test
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
sendActionToRoute() {
this.send('actionOnRoute');
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
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();
import { moduleFor, test } from 'ember-qunit';
import { run } from '@ember/runloop';
moduleFor('controller:my-controller', 'Unit | Controller | my-controller', {
});
test('it sends an action to route', function(assert) {
let controller = this.subject({
target: {
send(action) {
assert.step('send method of route');
assert.equal(action, 'actionOnRoute', 'correct action is triggered on route');
}
}
});
controller.send('sendActionToRoute');
assert.verifySteps(['send method of route']);
});
{
"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.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment