Skip to content

Commit

Permalink
Add test for conditional on to try to reproduce emberjs/ember.js#20647
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Feb 13, 2024
1 parent 1cb493b commit a8d96bf
Showing 1 changed file with 30 additions and 4 deletions.
Expand Up @@ -315,11 +315,37 @@ if (hasDom) {
this.assertCounts({ adds: 1, removes: 0 });
}

@test
'updates to a (remaining truthy) condition do not leave the element without an attached modifier'(assert:
Assert) {
let calledCount = 0;

this.render('<button {{on "click" this.callback}}>Click Me</button>', {
callback() {
calledCount++;
},
condition: true,
});

this.findButton().click();
assert.strictEqual(calledCount, 1, 'callback is being invoked');

this.rerender({ condition: true });

this.findButton().click();
assert.strictEqual(calledCount, 2, 'callback is being invoked');

this.rerender({ condition: true });

this.findButton().click();
assert.strictEqual(calledCount, 3, 'callback is being invoked');
}

@test
'asserts when eventName is missing'(assert: Assert) {
assert.throws(() => {
this.render(`<button {{on undefined this.callback}}>Click Me</button>`, {
callback() {},
callback() { },
});
}, /You must pass a valid DOM event name as the first argument to the `on` modifier/u);
}
Expand All @@ -328,7 +354,7 @@ if (hasDom) {
'asserts when eventName is a bound undefined value'(assert: Assert) {
assert.throws(() => {
this.render(`<button {{on this.someUndefinedThing this.callback}}>Click Me</button>`, {
callback() {},
callback() { },
});
}, /You must pass a valid DOM event name as the first argument to the `on` modifier/u);
}
Expand All @@ -337,7 +363,7 @@ if (hasDom) {
'asserts when eventName is a function'(assert: Assert) {
assert.throws(() => {
this.render(`<button {{on this.callback}}>Click Me</button>`, {
callback() {},
callback() { },
});
}, /You must pass a valid DOM event name as the first argument to the `on` modifier/u);
}
Expand Down Expand Up @@ -384,7 +410,7 @@ if (hasDom) {
'asserts if more than 2 positional parameters are provided'(assert: Assert) {
assert.throws(() => {
this.render(`<button {{on 'click' this.callback this.someArg}}>Click Me</button>`, {
callback() {},
callback() { },
someArg: 'foo',
});
}, /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);
Expand Down

0 comments on commit a8d96bf

Please sign in to comment.