Using arrow functions changes `this` context, which is undesired in tests, e.g. it makes it impossible to setup things like pretender (`this.server`) in `beforeEach` hooks. Ember guides always use classic functions in examples (e.g. https://guides.emberjs.com/release/testing/test-types/), and that's what it uses in its own test suite, as do various addons and ember apps. It was also already used in Discourse where `this` was required. Moving forward, it will be needed in more places as we migrate toward ember-cli. (I might later add a custom rule to eslint-discourse-ember to enforce this)
72 lines
1.5 KiB
JavaScript
72 lines
1.5 KiB
JavaScript
import { test, module } from "qunit";
|
||
import Sharing from "discourse/lib/sharing";
|
||
|
||
module("lib:sharing", {
|
||
beforeEach() {
|
||
Sharing._reset();
|
||
},
|
||
afterEach() {
|
||
Sharing._reset();
|
||
},
|
||
});
|
||
|
||
test("addSource", function (assert) {
|
||
const sharingSettings = "facebook|twitter";
|
||
|
||
assert.blank(Sharing.activeSources(sharingSettings));
|
||
|
||
Sharing.addSource({
|
||
id: "facebook",
|
||
});
|
||
|
||
assert.equal(Sharing.activeSources(sharingSettings).length, 1);
|
||
});
|
||
|
||
test("addSharingId", function (assert) {
|
||
const sharingSettings = "";
|
||
|
||
assert.blank(Sharing.activeSources(sharingSettings));
|
||
|
||
Sharing.addSource({
|
||
id: "new-source",
|
||
});
|
||
|
||
assert.blank(
|
||
Sharing.activeSources(sharingSettings),
|
||
"it doesn’t activate a source not in settings"
|
||
);
|
||
|
||
Sharing.addSharingId("new-source");
|
||
|
||
assert.equal(
|
||
Sharing.activeSources(sharingSettings).length,
|
||
1,
|
||
"it adds sharing id to existing sharing settings"
|
||
);
|
||
|
||
const privateContext = true;
|
||
|
||
Sharing.addSource({
|
||
id: "another-source",
|
||
});
|
||
Sharing.addSharingId("another-source");
|
||
|
||
assert.equal(
|
||
Sharing.activeSources(sharingSettings, privateContext).length,
|
||
0,
|
||
"it does not add a regular source to sources in a private context"
|
||
);
|
||
|
||
Sharing.addSource({
|
||
id: "a-private-friendly-source",
|
||
showInPrivateContext: true,
|
||
});
|
||
Sharing.addSharingId("a-private-friendly-source");
|
||
|
||
assert.equal(
|
||
Sharing.activeSources(sharingSettings, privateContext).length,
|
||
1,
|
||
"it does not add a regular source to sources in a private context"
|
||
);
|
||
});
|