Skip to content

Commit

Permalink
[BUGFIX beta] Provide a helpful error for undefined closure actions.
Browse files Browse the repository at this point in the history
In the following scenario:

```handlebars
{{#foo-bar blah=(action somethingThatIsUndefined)}}
  Click Me!
{{/foo-bar}}
```

Previously, an error was only thrown when attempting to invoke
`this.attrs.blah()`.  After this change a helpful error like the following
will be thrown:

```
An action could not be made for `somethingThatIsUndefined` in
< component object id>.  Please confirm that you are using either
a quoted action name (i.e. `(action 'somethingThatIsUndefined')`)
or a function available in < component object id>.
```
  • Loading branch information
rwjblue committed Aug 30, 2015
1 parent 7d76ff7 commit eb01971
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export default function closureAction(morph, env, scope, params, hash, template,
// look to "target".
target = read(scope.self);
action = read(rawAction);
if (typeof action === 'string') {
let actionType = typeof action;

if (actionType === 'string') {
let actionName = action;
action = null;
// on-change={{action 'setName'}}
Expand All @@ -42,6 +44,8 @@ export default function closureAction(morph, env, scope, params, hash, template,
if (!action) {
throw new EmberError(`An action named '${actionName}' was not found in ${target}.`);
}
} else if (actionType !== 'function') {
throw new EmberError(`An action could not be made for \`${rawAction.label}\` in ${target}. Please confirm that you are using either a quoted action name (i.e. \`(action '${rawAction.label}')\`) or a function available in ${target}.`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ QUnit.test('action should be called', function(assert) {
});
});

QUnit.test('an error is triggered when bound action function is undefined', function(assert) {
assert.expect(1);

innerComponent = EmberComponent.extend({
}).create();

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

throws(function() {
runAppend(outerComponent);
}, /An action could not be made for `somethingThatIsUndefined` in .*\. Please confirm that you are using either a quoted action name \(i\.e\. `\(action 'somethingThatIsUndefined'\)`\) or a function available in .*\./);
});

QUnit.test('action value is returned', function(assert) {
assert.expect(1);

Expand Down

0 comments on commit eb01971

Please sign in to comment.