Skip to content

Commit

Permalink
Add test for non-interactive on modifier lifecycle hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
CvX committed May 29, 2019
1 parent 4f8b716 commit 13e422a
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { isChrome, isFirefox } from '@ember/-internals/browser-environment';
import { privatize as P } from '@ember/-internals/container';
import { HAS_NATIVE_PROXY } from '@ember/-internals/utils';

import { Component } from '../../utils/helpers';

const isIE11 = !window.ActiveXObject && 'ActiveXObject' in window;

if (EMBER_GLIMMER_ON_MODIFIER) {
Expand Down Expand Up @@ -379,4 +381,63 @@ if (EMBER_GLIMMER_ON_MODIFIER) {
}
}
);

moduleFor(
'Rendering test: non-interactive `on` modifier',
class extends RenderingTestCase {
getBootOptions() {
return { isInteractive: false };
}

beforeEach() {
// might error if getOnManagerInstance fails
this.startingCounters = this.getOnManagerInstance().counters;
}

getOnManagerInstance() {
// leveraging private APIs, this can be deleted if these APIs change
// but it has been useful to verify some internal details
let templateCompiler = this.owner.lookup(P`template-compiler:main`);

return templateCompiler.resolver.resolver.builtInModifiers.on.manager;
}

assertCounts(expected) {
let { counters } = this.getOnManagerInstance();

this.assert.deepEqual(
counters,
{
adds: expected.adds + this.startingCounters.adds,
removes: expected.removes + this.startingCounters.removes,
},
`counters have incremented by ${JSON.stringify(expected)}`
);
}

[`@test doesn't trigger lifecycle hooks when non-interactive`](assert) {
this.registerComponent('foo-bar2', {
ComponentClass: Component.extend({
tagName: '',
fire() {
assert.ok(false);
},
}),
template: `<button {{on 'click' this.fire}}>Fire!</button>`,
});

this.render('{{#if this.showButton}}<FooBar2 />{{/if}}', {
showButton: true,
});
this.assertHTML('<button>Fire!</button>');
this.assertCounts({ adds: 0, removes: 0 });

this.$('button').click();

runTask(() => this.context.set('showButton', false));

this.assertCounts({ adds: 0, removes: 0 });
}
}
);
}

0 comments on commit 13e422a

Please sign in to comment.