@@ -269,6 +269,44 @@ function basicTest(scenarios: Scenarios, appName: string) {
269269 let allNodes = flattenTree(tree);
270270 let names = allNodes.filter(n => n.type === 'component').map(n => n.name);
271271 assert.true(names.includes('HelloWorld'), 'HelloWorld component name is preserved in the render tree (found: ' + names.join(', ') + ')');
272+ });
273+ });
274+ ` ,
275+ 'on-modifier-error-test.gjs' : `
276+ import { module, test } from 'qunit';
277+ import { render, setupOnerror, resetOnerror } from '@ember/test-helpers';
278+ import { setupRenderingTest } from 'ember-qunit';
279+ import { on } from '@ember/modifier';
280+
281+ module('on modifier | error handling', function (hooks) {
282+ setupRenderingTest(hooks);
283+
284+ hooks.afterEach(function () {
285+ resetOnerror();
286+ });
287+
288+ test('throws helpful error when callback is undefined', async function (assert) {
289+ assert.expect(1);
290+ const noop = undefined;
291+ setupOnerror((error) => {
292+ assert.true(
293+ /You must pass a function as the second argument to the \`on\` modifier/.test(error.message),
294+ 'Expected helpful error message, got: ' + error.message
295+ );
296+ });
297+ await render(<template><div {{on "click" noop}}>Click</div></template>);
298+ });
299+
300+ test('throws helpful error when callback is null', async function (assert) {
301+ assert.expect(1);
302+ const noop = null;
303+ setupOnerror((error) => {
304+ assert.true(
305+ /You must pass a function as the second argument to the \`on\` modifier/.test(error.message),
306+ 'Expected helpful error message, got: ' + error.message
307+ );
308+ });
309+ await render(<template><div {{on "click" noop}}>Click</div></template>);
272310 });
273311 });
274312 ` ,
0 commit comments