Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Provide useful errors when a closure action is not found. #11348

Merged
merged 1 commit into from Jun 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/ember-routing-htmlbars/lib/keywords/closure-action.js
Expand Up @@ -7,6 +7,7 @@ import {
import keys from 'ember-metal/keys';
import { symbol } from "ember-metal/utils";
import { get } from "ember-metal/property_get";
import EmberError from "ember-metal/error";

export const INVOKE = symbol("INVOKE");
export const ACTION = symbol('ACTION');
Expand All @@ -33,15 +34,21 @@ export default function closureAction(morph, env, scope, params, hash, template,
target = read(scope.self);
action = read(rawAction);
if (typeof action === 'string') {
let actionName = action;
action = null;
// on-change={{action 'setName'}}
if (hash.target) {
// on-change={{action 'setName' target=alternativeComponent}}
target = read(hash.target);
}
if (target.actions) {
action = target.actions[action];
} else {
action = target._actions[action];
action = target.actions[actionName];
} else if (target._actions) {
action = target._actions[actionName];
}

if (!action) {
throw new EmberError(`An action named '${actionName}' was not found in ${target}.`);
}
}
}
Expand Down
Expand Up @@ -289,6 +289,47 @@ if (Ember.FEATURES.isEnabled("ember-routing-htmlbars-improved-actions")) {
});
});

QUnit.test("provides a helpful error if an action is not present", function(assert) {
assert.expect(1);

innerComponent = EmberComponent.create();

outerComponent = EmberComponent.extend({
layout: compile(`
{{view innerComponent submit=(action 'doesNotExist')}}
`),
innerComponent,
actions: {
something() {
// this is present to ensure `actions` hash is present
// a different error is triggered if `actions` is missing
// completely
}
}
}).create();

throws(function() {
runAppend(outerComponent);
}, /An action named 'doesNotExist' was not found in /);
});

QUnit.test("provides a helpful error if actions hash is not present", function(assert) {
assert.expect(1);

innerComponent = EmberComponent.create();

outerComponent = EmberComponent.extend({
layout: compile(`
{{view innerComponent submit=(action 'doesNotExist')}}
`),
innerComponent
}).create();

throws(function() {
runAppend(outerComponent);
}, /An action named 'doesNotExist' was not found in /);
});

QUnit.test("action can create closures over actions with target", function(assert) {
assert.expect(1);

Expand Down