Refactor tests to not rely on globals

This commit is contained in:
stoically
2020-01-24 08:16:15 +01:00
parent 53baee1d5c
commit 405e605ba3
10 changed files with 213 additions and 311 deletions
+19 -12
View File
@@ -1,17 +1,24 @@
describe("External Webextensions", () => {
const {expect, initializeWithTab} = require("../common");
describe("External Webextensions", function () {
const url = "http://example.com";
beforeEach(async () => {
await helper.browser.initializeWithTab({
beforeEach(async function () {
this.webExt = await initializeWithTab({
cookieStoreId: "firefox-container-1",
url
});
await helper.popup.clickElementById("container-page-assigned");
await this.webExt.popup.helper.clickElementById("container-page-assigned");
});
describe("with contextualIdentities permissions", () => {
it("should be able to get assignments", async () => {
background.browser.management.get.resolves({
afterEach(function () {
this.webExt.destroy();
});
describe("with contextualIdentities permissions", function () {
it("should be able to get assignments", async function () {
this.webExt.background.browser.management.get.resolves({
permissions: ["contextualIdentities"]
});
@@ -23,7 +30,7 @@ describe("External Webextensions", () => {
id: "external-webextension"
};
const [promise] = background.browser.runtime.onMessageExternal.addListener.yield(message, sender);
const [promise] = this.webExt.background.browser.runtime.onMessageExternal.addListener.yield(message, sender);
const answer = await promise;
expect(answer.userContextId === "1").to.be.true;
expect(answer.neverAsk === false).to.be.true;
@@ -33,9 +40,9 @@ describe("External Webextensions", () => {
});
});
describe("without contextualIdentities permissions", () => {
it("should throw an error", async () => {
background.browser.management.get.resolves({
describe("without contextualIdentities permissions", function () {
it("should throw an error", async function () {
this.webExt.background.browser.management.get.resolves({
permissions: []
});
@@ -47,7 +54,7 @@ describe("External Webextensions", () => {
id: "external-webextension"
};
const [promise] = background.browser.runtime.onMessageExternal.addListener.yield(message, sender);
const [promise] = this.webExt.background.browser.runtime.onMessageExternal.addListener.yield(message, sender);
return promise.catch(error => {
expect(error.message).to.equal("Missing contextualIdentities permission");
});