Skip to content

Commit 53ece6a

Browse files
committed
[BUGFIX]: throws helpful error when event name is missing in {{on}} modifier.
+ Cleanup redundant test from 5b6f80b
1 parent b468185 commit 53ece6a

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

packages/@glimmer/runtime/lib/modifiers/on.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
CheckString,
1515
CheckUndefined,
1616
} from '@glimmer/debug';
17-
import { buildUntouchableThis, localAssert } from '@glimmer/debug-util';
17+
import { buildUntouchableThis } from '@glimmer/debug-util';
1818
import { registerDestructor } from '@glimmer/destroyable';
1919
import { setInternalModifierManager } from '@glimmer/manager';
2020
import { valueForRef } from '@glimmer/reference';
@@ -57,13 +57,16 @@ export class OnModifierState {
5757
updateListener(): void {
5858
let { element, args, listener } = this;
5959

60-
localAssert(
61-
args.positional[0],
62-
'You must pass a valid DOM event name as the first argument to the `on` modifier'
63-
);
60+
let arg0 = args.positional[0];
61+
62+
if (DEBUG && !arg0) {
63+
throw new Error(
64+
'You must pass a valid DOM event name as the first argument to the `on` modifier'
65+
);
66+
}
6467

6568
let eventName = check(
66-
valueForRef(args.positional[0]),
69+
arg0 ? valueForRef(arg0) : undefined,
6770
CheckString,
6871
() => 'You must pass a valid DOM event name as the first argument to the `on` modifier'
6972
);

smoke-tests/scenarios/basic-test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ function basicTest(scenarios: Scenarios, appName: string) {
285285
resetOnerror();
286286
});
287287
288-
test('throws helpful error when callback is undefined', async function (assert) {
288+
test('throws helpful error when callback is missing', async function (assert) {
289289
assert.expect(1);
290290
const noop = undefined;
291291
setupOnerror((error) => {
@@ -297,16 +297,16 @@ function basicTest(scenarios: Scenarios, appName: string) {
297297
await render(<template><div {{on "click" noop}}>Click</div></template>);
298298
});
299299
300-
test('throws helpful error when callback is null', async function (assert) {
300+
test('throws helpful error when event name is missing', async function (assert) {
301301
assert.expect(1);
302-
const noop = null;
302+
const noop = () => {};
303303
setupOnerror((error) => {
304304
assert.true(
305-
/You must pass a function as the second argument to the \`on\` modifier/.test(error.message),
305+
/You must pass a valid DOM event name as the first argument to the \`on\` modifier/.test(error.message),
306306
'Expected helpful error message, got: ' + error.message
307307
);
308308
});
309-
await render(<template><div {{on "click" noop}}>Click</div></template>);
309+
await render(<template><div {{on}}>Click</div></template>);
310310
});
311311
});
312312
`,

0 commit comments

Comments
 (0)