Skip to content

Commit a8d96bf

Browse files
committed
Add test for conditional on to try to reproduce emberjs/ember.js#20647
1 parent 1cb493b commit a8d96bf

File tree

1 file changed

+30
-4
lines changed
  • packages/@glimmer-workspace/integration-tests/test/modifiers

1 file changed

+30
-4
lines changed

packages/@glimmer-workspace/integration-tests/test/modifiers/on-test.ts

+30-4
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,37 @@ if (hasDom) {
315315
this.assertCounts({ adds: 1, removes: 0 });
316316
}
317317

318+
@test
319+
'updates to a (remaining truthy) condition do not leave the element without an attached modifier'(assert:
320+
Assert) {
321+
let calledCount = 0;
322+
323+
this.render('<button {{on "click" this.callback}}>Click Me</button>', {
324+
callback() {
325+
calledCount++;
326+
},
327+
condition: true,
328+
});
329+
330+
this.findButton().click();
331+
assert.strictEqual(calledCount, 1, 'callback is being invoked');
332+
333+
this.rerender({ condition: true });
334+
335+
this.findButton().click();
336+
assert.strictEqual(calledCount, 2, 'callback is being invoked');
337+
338+
this.rerender({ condition: true });
339+
340+
this.findButton().click();
341+
assert.strictEqual(calledCount, 3, 'callback is being invoked');
342+
}
343+
318344
@test
319345
'asserts when eventName is missing'(assert: Assert) {
320346
assert.throws(() => {
321347
this.render(`<button {{on undefined this.callback}}>Click Me</button>`, {
322-
callback() {},
348+
callback() { },
323349
});
324350
}, /You must pass a valid DOM event name as the first argument to the `on` modifier/u);
325351
}
@@ -328,7 +354,7 @@ if (hasDom) {
328354
'asserts when eventName is a bound undefined value'(assert: Assert) {
329355
assert.throws(() => {
330356
this.render(`<button {{on this.someUndefinedThing this.callback}}>Click Me</button>`, {
331-
callback() {},
357+
callback() { },
332358
});
333359
}, /You must pass a valid DOM event name as the first argument to the `on` modifier/u);
334360
}
@@ -337,7 +363,7 @@ if (hasDom) {
337363
'asserts when eventName is a function'(assert: Assert) {
338364
assert.throws(() => {
339365
this.render(`<button {{on this.callback}}>Click Me</button>`, {
340-
callback() {},
366+
callback() { },
341367
});
342368
}, /You must pass a valid DOM event name as the first argument to the `on` modifier/u);
343369
}
@@ -384,7 +410,7 @@ if (hasDom) {
384410
'asserts if more than 2 positional parameters are provided'(assert: Assert) {
385411
assert.throws(() => {
386412
this.render(`<button {{on 'click' this.callback this.someArg}}>Click Me</button>`, {
387-
callback() {},
413+
callback() { },
388414
someArg: 'foo',
389415
});
390416
}, /You can only pass two positional arguments \(event name and callback\) to the `on` modifier, but you provided 3. Consider using the `fn` helper to provide additional arguments to the `on` callback./u);

0 commit comments

Comments
 (0)