mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
DEV: adds afterRender decorator (#8864)
This commit is contained in:
@ -3,10 +3,12 @@ import selectKit from "helpers/select-kit-helper";
|
||||
export function testSelectKitModule(moduleName, options = {}) {
|
||||
moduleForComponent(`select-kit/${moduleName}`, {
|
||||
integration: true,
|
||||
|
||||
beforeEach() {
|
||||
this.set("subject", selectKit());
|
||||
options.beforeEach && options.beforeEach.call(this);
|
||||
},
|
||||
|
||||
afterEach() {
|
||||
options.afterEach && options.afterEach.call(this);
|
||||
}
|
||||
|
49
test/javascripts/utils/decorators-test.js.es6
Normal file
49
test/javascripts/utils/decorators-test.js.es6
Normal file
@ -0,0 +1,49 @@
|
||||
import { afterRender } from "discourse-common/utils/decorators";
|
||||
import Component from "@ember/component";
|
||||
import componentTest from "helpers/component-test";
|
||||
|
||||
const fooComponent = Component.extend({
|
||||
layoutName: "foo-component",
|
||||
|
||||
classNames: ["foo-component"],
|
||||
|
||||
baz: null,
|
||||
|
||||
didInsertElement() {
|
||||
this._super(...arguments);
|
||||
|
||||
this.setBaz(1);
|
||||
},
|
||||
|
||||
willDestroyElement() {
|
||||
this._super(...arguments);
|
||||
|
||||
this.setBaz(2);
|
||||
},
|
||||
|
||||
@afterRender
|
||||
setBaz(baz) {
|
||||
this.set("baz", baz);
|
||||
}
|
||||
});
|
||||
|
||||
moduleForComponent("utils:decorators", { integration: true });
|
||||
|
||||
componentTest("afterRender", {
|
||||
template: "{{foo-component baz=baz}}",
|
||||
|
||||
beforeEach() {
|
||||
this.registry.register("component:foo-component", fooComponent);
|
||||
this.set("baz", 0);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(exists(document.querySelector(".foo-component")));
|
||||
assert.equal(this.baz, 1);
|
||||
|
||||
this.clearRender();
|
||||
|
||||
assert.ok(!exists(document.querySelector(".foo-component")));
|
||||
assert.equal(this.baz, 1);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user