From e44b4d769f1663d6c0218845a06fa639d3646511 Mon Sep 17 00:00:00 2001 From: Stanley Stuart Date: Wed, 24 Jan 2024 21:10:59 -0800 Subject: [PATCH] [failing test] add test for adding/removing/re-adding modifier with `if` This test currently fails if the modifier is inside an `(if)` statement, and if the condition changes from true -> false -> true. It seems like somehow when the 3rd re-render to true happens, the `modifier` helper gets a clone of the first two positional arguments (the event name and the callback). The `modifier` helper gets 4 arguments when it should only be getting two. --- .../tests/integration/modifiers/on-test.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/@ember/-internals/glimmer/tests/integration/modifiers/on-test.js b/packages/@ember/-internals/glimmer/tests/integration/modifiers/on-test.js index 7d9556715a8..17a8b1f83e4 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/modifiers/on-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/modifiers/on-test.js @@ -267,6 +267,37 @@ moduleFor( this.assertCounts({ adds: 1, removes: 1 }); } + + [`@test can be set or unset dynamically multiple times on an element`](assert) { + let wasCalled = false; + let toggle = () => (wasCalled = !wasCalled); + + this.render( + '', + { + bindClick: false, + toggle, + on, + } + ); + + this.$('button').click(); + assert.false(wasCalled); + + runTask(() => this.context.set('bindClick', true)); + + this.$('button').click(); + assert.true(wasCalled); + + wasCalled = false; + runTask(() => this.context.set('bindClick', false)); + this.$('button').click(); + assert.false(wasCalled); + + runTask(() => this.context.set('bindClick', true)); + this.$('button').click(); + assert.true(wasCalled); + } } );