Skip to content

Commit 0378e2a

Browse files
author
Joel Kang
committed
Make view layer send() method user asser instead of throwing to allow tests to properly expect it
1 parent 06948d4 commit 0378e2a

File tree

4 files changed

+46
-51
lines changed

4 files changed

+46
-51
lines changed

packages/ember-glimmer/lib/ember-views/target-action-support.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,14 @@ export default Mixin.create(TargetActionSupport, {
7171

7272
if (target = get(this, 'target')) {
7373
assert(
74-
'The `target` for ' + this + ' (' + target +
74+
'The `target` for ' + inspect(this) + ' (' + target +
7575
') does not have a `send` method',
7676
typeof target.send === 'function'
7777
);
7878
target.send(...arguments);
79-
} else {
80-
if (!action) {
81-
throw new Error(inspect(this) + ' had no action handler for: ' + actionName);
82-
}
79+
return;
8380
}
81+
assert(`${inspect(this)} had no action handler for: ${actionName}`, action);
8482
},
8583
/**
8684
TODO: This looks like it's not even used by the view layer. Deprecate and remove?
@@ -106,7 +104,6 @@ export default Mixin.create(TargetActionSupport, {
106104
}
107105
return null;
108106
}),
109-
110107
/**
111108
Calls a action passed to a component.
112109
For example a component for playing or pausing music may translate click events

packages/ember-glimmer/lib/syntax/curly-component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function applyAttributeBindings(attributeBindings, component, operations) {
4242
function privatizeTargetObject(props) {
4343
if (props.targetObject) {
4444
props._targetObject = props.targetObject;
45-
delete props.targetObject;
45+
props.targetObject = undefined;
4646
}
4747
}
4848

packages/ember-glimmer/tests/integration/components/target-action-test.js

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,17 @@ moduleFor('Components test: sendAction', class extends RenderingTest {
200200
moduleFor('Components test: sendAction to a controller', class extends ApplicationTest {
201201

202202
['@test sendAction should trigger an action on the parent component\'s controller if it exists'](assert) {
203-
assert.expect(7);
203+
assert.expect(10);
204204

205205
let component;
206206

207207
this.router.map(function () {
208+
this.route('withController');
209+
this.route('withoutController');
208210
this.route('withNestedController', function () {
209211
this.route('nestedWithController');
210212
this.route('nestedWithoutController');
211213
});
212-
this.route('withController');
213-
this.route('withoutController');
214214
});
215215

216216
this.registerComponent('foo-bar', {
@@ -222,52 +222,64 @@ moduleFor('Components test: sendAction to a controller', class extends Applicati
222222
})
223223
});
224224

225-
this.registerTemplate('withNestedController', '{{foo-bar poke="poke"}}{{outlet}}');
226-
this.registerTemplate('withController', '{{foo-bar poke="poke"}}');
227-
this.registerTemplate('withoutController', '{{foo-bar poke="poke"}}');
228-
this.registerTemplate('withNestedController.nestedWithController', '{{foo-bar poke="poke"}}');
229-
this.registerTemplate('withNestedController.nestedWithoutController', '{{foo-bar poke="poke"}}');
230-
225+
this.registerRoute('withController', Route);
231226
this.registerController('withController', Controller.extend({
232227
send(actionName, actionContext) {
233228
assert.equal(actionName, 'poke', 'send() method was invoked from a top level controller');
234229
assert.equal(actionContext, 'top', 'action arguments were passed into the top level controller');
235230
}
236231
}));
232+
this.registerTemplate('withController', '{{foo-bar poke="poke"}}');
233+
234+
this.registerRoute('withoutController', Route.extend({
235+
actions: {
236+
poke(actionContext) {
237+
assert.ok(true, 'Unhandled action sent to route');
238+
assert.equal(actionContext, 'top no controller');
239+
}
240+
}
241+
}));
242+
this.registerTemplate('withoutController', '{{foo-bar poke="poke"}}');
237243

244+
this.registerRoute('withNestedController', Route.extend({
245+
actions: {
246+
poke(actionContext) {
247+
assert.ok(true, 'Unhandled action sent to route');
248+
assert.equal(actionContext, 'top with nested no controller');
249+
}
250+
}
251+
}));
252+
this.registerTemplate('withNestedController', '{{foo-bar poke="poke"}}{{outlet}}');
253+
254+
this.registerRoute('withNestedController.nestedWithController', Route);
238255
this.registerController('withNestedControllerNestedWithController', Controller.extend({
239256
send(actionName, actionContext) {
240257
assert.equal(actionName, 'poke', 'send() method was invoked from a nested controller');
241258
assert.equal(actionContext, 'nested', 'action arguments were passed into the nested controller');
242259
}
243260
}));
261+
this.registerTemplate('withNestedController.nestedWithController', '{{foo-bar poke="poke"}}');
244262

245-
this.registerRoute('withController', Route);
246-
this.registerRoute('withNestedController', Route);
247-
this.registerRoute('withNestedController.nestedWithController', Route);
248-
this.registerRoute('withNestedController.nestedWithOutController', Route);
249-
this.registerRoute('withoutController', Route);
250-
251-
function expectSendActionToThrow() {
252-
let fn = () => component.sendAction('poke');
253-
if (EmberDev && EmberDev.runningProdBuild) {
254-
expectAssertion(fn);
255-
} else {
256-
assert.throws(fn);
263+
this.registerRoute('withNestedController.nestedWithoutController', Route.extend({
264+
actions: {
265+
poke(actionContext) {
266+
assert.ok(true, 'Unhandled action sent to route');
267+
assert.equal(actionContext, 'nested no controller');
268+
}
257269
}
258-
}
270+
}));
271+
this.registerTemplate('withNestedController.nestedWithoutController', '{{foo-bar poke="poke"}}');
259272

260273
return this.visit('/withController')
261274
.then(() => component.sendAction('poke', 'top'))
262-
.then(() => this.visit('withoutController'))
263-
.then(expectSendActionToThrow)
264-
// withNestedController.index does not have a controller specified, so it should throw
275+
.then(() => this.visit('/withoutController'))
276+
.then(() => component.sendAction('poke', 'top no controller'))
265277
.then(() => this.visit('/withNestedController'))
266-
.then(expectSendActionToThrow)
278+
.then(() => component.sendAction('poke', 'top with nested no controller'))
267279
.then(() => this.visit('/withNestedController/nestedWithController'))
268280
.then(() => component.sendAction('poke', 'nested'))
269281
.then(() => this.visit('/withNestedController/nestedWithoutController'))
270-
.then(expectSendActionToThrow);
282+
.then(() => component.sendAction('poke', 'nested no controller'));
271283
}
272284

273285
['@test sendAction should not trigger an action an outlet\'s controller if a parent component handles it'](assert) {
@@ -310,7 +322,7 @@ moduleFor('Components test: sendAction to a controller', class extends Applicati
310322
moduleFor('Components test: sendAction of a closure action', class extends RenderingTest {
311323

312324
['@test action should be called'](assert) {
313-
this.assert.expect(1);
325+
assert.expect(1);
314326
let component;
315327

316328
this.registerComponent('inner-component', {
@@ -400,8 +412,8 @@ moduleFor('Components test: send', class extends RenderingTest {
400412

401413
this.runTask(() => component.send('foo', 'bar'));
402414

403-
expectAssertion(function () {
404-
component.send('baz', 'bar');
415+
expectAssertion(() => {
416+
return component.send('baz', 'bar');
405417
}, /had no action handler for: baz/);
406418
}
407419

packages/ember-glimmer/tests/utils/abstract-test-case.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -313,20 +313,6 @@ export class ApplicationTest extends TestCase {
313313
registerController(name, controller) {
314314
this.application.register(`controller:${name}`, controller);
315315
}
316-
317-
registerComponent(name, { ComponentClass = null, template = null }) {
318-
let { application } = this;
319-
320-
if (ComponentClass) {
321-
application.register(`component:${name}`, ComponentClass);
322-
}
323-
324-
if (typeof template === 'string') {
325-
application.register(`template:components/${name}`, compile(template, {
326-
moduleName: `components/${name}`
327-
}));
328-
}
329-
}
330316
}
331317

332318
export class RenderingTest extends TestCase {

0 commit comments

Comments
 (0)