aboutsummaryrefslogtreecommitdiff
path: root/test/background
diff options
context:
space:
mode:
Diffstat (limited to 'test/background')
-rw-r--r--test/background/completion/OpenCompletionUseCase.test.ts102
-rw-r--r--test/background/completion/PropertyCompletionUseCase.test.ts5
-rw-r--r--test/background/completion/TabCompletionUseCase.test.ts104
-rw-r--r--test/background/completion/impl/filters.test.ts15
-rw-r--r--test/background/infrastructures/MemoryStorage.test.ts15
-rw-r--r--test/background/mock/MockFramePresenter.ts7
-rw-r--r--test/background/operators/impls/CancelOperator.test.ts10
-rw-r--r--test/background/operators/impls/CloseTabOperator.test.ts7
-rw-r--r--test/background/operators/impls/CloseTabRightOperator.test.ts3
-rw-r--r--test/background/operators/impls/CommandOperatorFactoryChain.test.ts15
-rw-r--r--test/background/operators/impls/DuplicateTabOperator.test.ts3
-rw-r--r--test/background/operators/impls/FindNextOperator.test.ts176
-rw-r--r--test/background/operators/impls/FindOperatorFactoryChain.ts5
-rw-r--r--test/background/operators/impls/FindPrevOperator.test.ts177
-rw-r--r--test/background/operators/impls/InternalOpenURLOperator.test.ts0
-rw-r--r--test/background/operators/impls/InternalOperatorFactoryChain.test.ts7
-rw-r--r--test/background/operators/impls/NavigateHistoryNextOperator.test.ts10
-rw-r--r--test/background/operators/impls/NavigateHistoryPrevOperator.test.ts10
-rw-r--r--test/background/operators/impls/NavigateLinkNextOperator.test.ts7
-rw-r--r--test/background/operators/impls/NavigateLinkPrevOperator.test.ts7
-rw-r--r--test/background/operators/impls/NavigateOperatorFactoryChain.test.ts19
-rw-r--r--test/background/operators/impls/NavigateParentOperator.test.ts9
-rw-r--r--test/background/operators/impls/NavigateRootOperator.test.ts3
-rw-r--r--test/background/operators/impls/OpenHomeOperator.test.ts10
-rw-r--r--test/background/operators/impls/OpenSourceOperator.test.ts3
-rw-r--r--test/background/operators/impls/PinTabOperator.test.ts3
-rw-r--r--test/background/operators/impls/ReloadTabOperator.test.ts16
-rw-r--r--test/background/operators/impls/ReopenTabOperator.test.ts7
-rw-r--r--test/background/operators/impls/RepeatLastOperator.test.ts25
-rw-r--r--test/background/operators/impls/RepeatOperatorFactoryChain.test.ts5
-rw-r--r--test/background/operators/impls/ResetZoomOperator.test.ts7
-rw-r--r--test/background/operators/impls/SelectFirstTabOperator.test.ts3
-rw-r--r--test/background/operators/impls/SelectLastTabOperator.test.ts3
-rw-r--r--test/background/operators/impls/SelectPreviousSelectedTabOperator.test.ts16
-rw-r--r--test/background/operators/impls/SelectTabNextOperator.test.ts5
-rw-r--r--test/background/operators/impls/SelectTabPrevOperator.test.ts5
-rw-r--r--test/background/operators/impls/ShowAddBookmarkOperator.test.ts19
-rw-r--r--test/background/operators/impls/ShowBufferCommandOperator.test.ts10
-rw-r--r--test/background/operators/impls/ShowCommandOperator.test.ts10
-rw-r--r--test/background/operators/impls/ShowOpenCommandOperator.test.ts19
-rw-r--r--test/background/operators/impls/ShowTabOpenCommandOperator.test.ts19
-rw-r--r--test/background/operators/impls/ShowWinOpenCommandOperator.test.ts19
-rw-r--r--test/background/operators/impls/StartFindOperator.test.ts7
-rw-r--r--test/background/operators/impls/TabOperatorFactoryChain.test.ts35
-rw-r--r--test/background/operators/impls/TogglePinnedTabOperator.test.ts5
-rw-r--r--test/background/operators/impls/UnpinTabOperator.test.ts3
-rw-r--r--test/background/operators/impls/ZoomInOperator.test.ts7
-rw-r--r--test/background/operators/impls/ZoomOperatorFactoryChain.test.ts9
-rw-r--r--test/background/operators/impls/ZoomOutOperator.test.ts7
-rw-r--r--test/background/repositories/FindRepository.test.ts13
-rw-r--r--test/background/repositories/Mark.test.ts11
-rw-r--r--test/background/repositories/ReadyFrameRepository.test.ts13
-rw-r--r--test/background/usecases/SettingUseCase.test.ts64
-rw-r--r--test/background/usecases/StartFindUseCase.test.ts229
-rw-r--r--test/background/usecases/parsers.test.ts30
55 files changed, 571 insertions, 782 deletions
diff --git a/test/background/completion/OpenCompletionUseCase.test.ts b/test/background/completion/OpenCompletionUseCase.test.ts
index f43e6c1..5ab9d5e 100644
--- a/test/background/completion/OpenCompletionUseCase.test.ts
+++ b/test/background/completion/OpenCompletionUseCase.test.ts
@@ -11,8 +11,6 @@ import CachedSettingRepository from "../../../src/background/repositories/Cached
import Settings, {
DefaultSetting,
} from "../../../src/shared/settings/Settings";
-import { expect } from "chai";
-import sinon from "sinon";
import Properties from "../../../src/shared/settings/Properties";
import Search from "../../../src/shared/settings/Search";
@@ -61,19 +59,17 @@ describe("OpenCompletionUseCase", () => {
describe("#getCompletionTypes", () => {
it("returns completion types from the property", async () => {
- sinon.stub(settingRepository, "get").returns(
- Promise.resolve(
- new Settings({
- keymaps: DefaultSetting.keymaps,
- search: DefaultSetting.search,
- properties: new Properties({ complete: "shb" }),
- blacklist: DefaultSetting.blacklist,
- })
- )
+ jest.spyOn(settingRepository, "get").mockResolvedValueOnce(
+ new Settings({
+ keymaps: DefaultSetting.keymaps,
+ search: DefaultSetting.search,
+ properties: new Properties({ complete: "shb" }),
+ blacklist: DefaultSetting.blacklist,
+ })
);
const items = await sut.getCompletionTypes();
- expect(items).to.deep.equal([
+ expect(items).toEqual([
CompletionType.SearchEngines,
CompletionType.History,
CompletionType.Bookmarks,
@@ -83,77 +79,73 @@ describe("OpenCompletionUseCase", () => {
describe("#requestSearchEngines", () => {
it("returns search engines matches by the query", async () => {
- sinon.stub(settingRepository, "get").returns(
- Promise.resolve(
- new Settings({
- keymaps: DefaultSetting.keymaps,
- search: new Search("google", {
- google: "https://google.com/search?q={}",
- yahoo: "https://search.yahoo.com/search?q={}",
- bing: "https://bing.com/search?q={}",
- googleja: "https://google.co.jp/search?q={}",
- }),
- properties: DefaultSetting.properties,
- blacklist: DefaultSetting.blacklist,
- })
- )
+ jest.spyOn(settingRepository, "get").mockResolvedValue(
+ new Settings({
+ keymaps: DefaultSetting.keymaps,
+ search: new Search("google", {
+ google: "https://google.com/search?q={}",
+ yahoo: "https://search.yahoo.com/search?q={}",
+ bing: "https://bing.com/search?q={}",
+ googleja: "https://google.co.jp/search?q={}",
+ }),
+ properties: DefaultSetting.properties,
+ blacklist: DefaultSetting.blacklist,
+ })
);
- expect(await sut.requestSearchEngines("")).to.deep.equal([
+ expect(await sut.requestSearchEngines("")).toEqual([
"google",
"yahoo",
"bing",
"googleja",
]);
- expect(await sut.requestSearchEngines("go")).to.deep.equal([
+ expect(await sut.requestSearchEngines("go")).toEqual([
"google",
"googleja",
]);
- expect(await sut.requestSearchEngines("x")).to.be.empty;
+ expect(await sut.requestSearchEngines("x")).toHaveLength(0);
});
});
describe("#requestBookmarks", () => {
it("returns bookmarks from the repository", async () => {
- sinon
- .stub(bookmarkRepository, "queryBookmarks")
- .withArgs("site")
- .returns(
- Promise.resolve([
- { title: "site1", url: "https://site1.example.com" },
- { title: "site2", url: "https://site2.example.com/" },
- ])
- )
- .withArgs("xyz")
- .returns(Promise.resolve([]));
+ const spy = jest
+ .spyOn(bookmarkRepository, "queryBookmarks")
+ .mockResolvedValueOnce([
+ { title: "site1", url: "https://site1.example.com" },
+ { title: "site2", url: "https://site2.example.com/" },
+ ])
+ .mockResolvedValueOnce([]);
- expect(await sut.requestBookmarks("site")).to.deep.equal([
+ expect(await sut.requestBookmarks("site")).toEqual([
{ title: "site1", url: "https://site1.example.com" },
{ title: "site2", url: "https://site2.example.com/" },
]);
- expect(await sut.requestBookmarks("xyz")).to.be.empty;
+ expect(await sut.requestBookmarks("xyz")).toHaveLength(0);
+ expect(spy).toBeCalledTimes(2);
+ expect(spy.mock.calls[0][0]).toEqual("site");
+ expect(spy.mock.calls[1][0]).toEqual("xyz");
});
});
describe("#requestHistory", () => {
it("returns histories from the repository", async () => {
- sinon
- .stub(historyRepository, "queryHistories")
- .withArgs("site")
- .returns(
- Promise.resolve([
- { title: "site1", url: "https://site1.example.com" },
- { title: "site2", url: "https://site2.example.com/" },
- ])
- )
- .withArgs("xyz")
- .returns(Promise.resolve([]));
+ const spy = jest
+ .spyOn(historyRepository, "queryHistories")
+ .mockResolvedValueOnce([
+ { title: "site1", url: "https://site1.example.com" },
+ { title: "site2", url: "https://site2.example.com/" },
+ ])
+ .mockResolvedValueOnce([]);
- expect(await sut.requestHistory("site")).to.deep.equal([
+ expect(await sut.requestHistory("site")).toEqual([
{ title: "site1", url: "https://site1.example.com" },
{ title: "site2", url: "https://site2.example.com/" },
]);
- expect(await sut.requestHistory("xyz")).to.be.empty;
+ expect(await sut.requestHistory("xyz")).toHaveLength(0);
+ expect(spy).toBeCalledTimes(2);
+ expect(spy.mock.calls[0][0]).toEqual("site");
+ expect(spy.mock.calls[1][0]).toEqual("xyz");
});
});
});
diff --git a/test/background/completion/PropertyCompletionUseCase.test.ts b/test/background/completion/PropertyCompletionUseCase.test.ts
index dfc989f..b008eb5 100644
--- a/test/background/completion/PropertyCompletionUseCase.test.ts
+++ b/test/background/completion/PropertyCompletionUseCase.test.ts
@@ -1,6 +1,5 @@
import "reflect-metadata";
import PropertyCompletionUseCase from "../../../src/background/completion/PropertyCompletionUseCase";
-import { expect } from "chai";
describe("PropertyCompletionUseCase", () => {
describe("getProperties", () => {
@@ -8,11 +7,11 @@ describe("PropertyCompletionUseCase", () => {
const sut = new PropertyCompletionUseCase();
const properties = await sut.getProperties();
- expect(properties).to.deep.contain({
+ expect(properties).toContainEqual({
name: "smoothscroll",
type: "boolean",
});
- expect(properties).to.deep.contain({ name: "complete", type: "string" });
+ expect(properties).toContainEqual({ name: "complete", type: "string" });
});
});
});
diff --git a/test/background/completion/TabCompletionUseCase.test.ts b/test/background/completion/TabCompletionUseCase.test.ts
index 319f217..c006b65 100644
--- a/test/background/completion/TabCompletionUseCase.test.ts
+++ b/test/background/completion/TabCompletionUseCase.test.ts
@@ -3,8 +3,6 @@ import TabRepositoryImpl from "../../../src/background/completion/impl/TabReposi
import { Tab } from "../../../src/background/completion/TabRepository";
import TabPresenter from "../../../src/background/presenters/TabPresenter";
import TabCompletionUseCase from "../../../src/background/completion/TabCompletionUseCase";
-import sinon from "sinon";
-import { expect } from "chai";
import TabFlag from "../../../src/shared/TabFlag";
class MockTabRepository implements TabRepositoryImpl {
@@ -98,43 +96,39 @@ describe("TabCompletionUseCase", () => {
tabPresenter = new MockTabPresenter();
sut = new TabCompletionUseCase(tabRepository, tabPresenter);
- sinon.stub(tabPresenter, "getLastSelectedId").returns(Promise.resolve(12));
- sinon.stub(tabRepository, "getAllTabs").returns(
- Promise.resolve([
- {
- id: 10,
- index: 0,
- title: "Google",
- url: "https://google.com/",
- faviconUrl: "https://google.com/favicon.ico",
- active: false,
- },
- {
- id: 11,
- index: 1,
- title: "Yahoo",
- url: "https://yahoo.com/",
- faviconUrl: "https://yahoo.com/favicon.ico",
- active: true,
- },
- {
- id: 12,
- index: 2,
- title: "Bing",
- url: "https://bing.com/",
- active: false,
- },
- ])
- );
+ jest.spyOn(tabPresenter, "getLastSelectedId").mockResolvedValue(12);
+ jest.spyOn(tabRepository, "getAllTabs").mockResolvedValue([
+ {
+ id: 10,
+ index: 0,
+ title: "Google",
+ url: "https://google.com/",
+ faviconUrl: "https://google.com/favicon.ico",
+ active: false,
+ },
+ {
+ id: 11,
+ index: 1,
+ title: "Yahoo",
+ url: "https://yahoo.com/",
+ faviconUrl: "https://yahoo.com/favicon.ico",
+ active: true,
+ },
+ {
+ id: 12,
+ index: 2,
+ title: "Bing",
+ url: "https://bing.com/",
+ active: false,
+ },
+ ]);
});
describe("#queryTabs", () => {
it("returns tab items", async () => {
- sinon
- .stub(tabRepository, "queryTabs")
- .withArgs("", false)
- .returns(
- Promise.resolve([
+ jest.spyOn(tabRepository, "queryTabs").mockImplementation((keyword) =>
+ Promise.resolve(
+ [
{
id: 10,
index: 0,
@@ -158,31 +152,13 @@ describe("TabCompletionUseCase", () => {
url: "https://bing.com/",
active: false,
},
- ])
+ ].filter(
+ (item) => item.title.includes(keyword) || item.url.includes(keyword)
+ )
)
- .withArgs("oo", false)
- .returns(
- Promise.resolve([
- {
- id: 10,
- index: 0,
- title: "Google",
- url: "https://google.com/",
- faviconUrl: "https://google.com/favicon.ico",
- active: false,
- },
- {
- id: 11,
- index: 1,
- title: "Yahoo",
- url: "https://yahoo.com/",
- faviconUrl: "https://yahoo.com/favicon.ico",
- active: true,
- },
- ])
- );
+ );
- expect(await sut.queryTabs("", false)).to.deep.equal([
+ expect(await sut.queryTabs("", false)).toEqual([
{
index: 1,
title: "Google",
@@ -206,7 +182,7 @@ describe("TabCompletionUseCase", () => {
},
]);
- expect(await sut.queryTabs("oo", false)).to.deep.equal([
+ expect(await sut.queryTabs("oo", false)).toEqual([
{
index: 1,
title: "Google",
@@ -225,7 +201,7 @@ describe("TabCompletionUseCase", () => {
});
it("returns a tab by the index", async () => {
- expect(await sut.queryTabs("1", false)).to.deep.equal([
+ expect(await sut.queryTabs("1", false)).toEqual([
{
index: 1,
title: "Google",
@@ -235,12 +211,12 @@ describe("TabCompletionUseCase", () => {
},
]);
- expect(await sut.queryTabs("10", false)).to.be.empty;
- expect(await sut.queryTabs("-1", false)).to.be.empty;
+ expect(await sut.queryTabs("10", false)).toHaveLength(0);
+ expect(await sut.queryTabs("-1", false)).toHaveLength(0);
});
it("returns the current tab by % flag", async () => {
- expect(await sut.queryTabs("%", false)).to.deep.equal([
+ expect(await sut.queryTabs("%", false)).toEqual([
{
index: 2,
title: "Yahoo",
@@ -252,7 +228,7 @@ describe("TabCompletionUseCase", () => {
});
it("returns the current tab by # flag", async () => {
- expect(await sut.queryTabs("#", false)).to.deep.equal([
+ expect(await sut.queryTabs("#", false)).toEqual([
{
index: 3,
title: "Bing",
diff --git a/test/background/completion/impl/filters.test.ts b/test/background/completion/impl/filters.test.ts
index b160944..5dd1a93 100644
--- a/test/background/completion/impl/filters.test.ts
+++ b/test/background/completion/impl/filters.test.ts
@@ -1,5 +1,4 @@
import * as filters from "../../../../src/background/completion/impl/filters";
-import { expect } from "chai";
describe("background/usecases/filters", () => {
describe("filterHttp", () => {
@@ -13,7 +12,7 @@ describe("background/usecases/filters", () => {
const filtered = filters.filterHttp(pages);
const urls = filtered.map((x) => x.url);
- expect(urls).to.deep.equal([
+ expect(urls).toEqual([
"https://i-beam.org/bar",
"http://i-beam.net/hoge",
"http://i-beam.net/fuga",
@@ -30,7 +29,7 @@ describe("background/usecases/filters", () => {
];
const filtered = filters.filterBlankTitle(pages);
- expect(filtered).to.deep.equal([{ id: "0", title: "hello" }]);
+ expect(filtered).toEqual([{ id: "0", title: "hello" }]);
});
});
@@ -45,7 +44,7 @@ describe("background/usecases/filters", () => {
const filtered = filters.filterByTailingSlash(pages);
const urls = filtered.map((x) => x.url);
- expect(urls).to.deep.equal([
+ expect(urls).toEqual([
"http://i-beam.org/content",
"http://i-beam.org/search",
"http://i-beam.org/search?q=apple_banana_cherry",
@@ -64,7 +63,7 @@ describe("background/usecases/filters", () => {
{ id: "5", url: "http://i-beam.org/request?q=apple_banana_cherry" },
];
const filtered = filters.filterByPathname(pages, 10);
- expect(filtered).to.have.lengthOf(6);
+ expect(filtered).toHaveLength(6);
});
it("filters by length of pathname", () => {
@@ -77,7 +76,7 @@ describe("background/usecases/filters", () => {
{ id: "5", url: "http://i-beam.net/search?q=apple_banana_cherry" },
];
const filtered = filters.filterByPathname(pages, 0);
- expect(filtered).to.deep.equal([
+ expect(filtered).toEqual([
{ id: "0", url: "http://i-beam.org/search?q=apple" },
{ id: "3", url: "http://i-beam.net/search?q=apple" },
]);
@@ -95,7 +94,7 @@ describe("background/usecases/filters", () => {
{ id: "5", url: "http://i-beam.org/request?q=apple_banana_cherry" },
];
const filtered = filters.filterByOrigin(pages, 10);
- expect(filtered).to.have.lengthOf(6);
+ expect(filtered).toHaveLength(6);
});
it("filters by length of pathname", () => {
@@ -108,7 +107,7 @@ describe("background/usecases/filters", () => {
{ id: "5", url: "http://i-beam.org/request?q=apple_banana_cherry" },
];
const filtered = filters.filterByOrigin(pages, 0);
- expect(filtered).to.deep.equal([
+ expect(filtered).toEqual([
{ id: "0", url: "http://i-beam.org/search?q=apple" },
]);
});
diff --git a/test/background/infrastructures/MemoryStorage.test.ts b/test/background/infrastructures/MemoryStorage.test.ts
index 1c67b18..6618549 100644
--- a/test/background/infrastructures/MemoryStorage.test.ts
+++ b/test/background/infrastructures/MemoryStorage.test.ts
@@ -1,22 +1,21 @@
import MemoryStorage from "../../../src/background/infrastructures/MemoryStorage";
-import { expect } from "chai";
describe("background/infrastructures/memory-storage", () => {
it("stores values", () => {
const cache = new MemoryStorage();
cache.set("number", 123);
- expect(cache.get("number")).to.equal(123);
+ expect(cache.get("number")).toEqual(123);
cache.set("string", "123");
- expect(cache.get("string")).to.equal("123");
+ expect(cache.get("string")).toEqual("123");
cache.set("object", { hello: "123" });
- expect(cache.get("object")).to.deep.equal({ hello: "123" });
+ expect(cache.get("object")).toEqual({ hello: "123" });
});
it("returns undefined if no keys", () => {
const cache = new MemoryStorage();
- expect(cache.get("no-keys")).to.be.undefined;
+ expect(cache.get("no-keys")).toBeUndefined;
});
it("stored on shared memory", () => {
@@ -25,7 +24,7 @@ describe("background/infrastructures/memory-storage", () => {
cache = new MemoryStorage();
const got = cache.get("red");
- expect(got).to.equal("apple");
+ expect(got).toEqual("apple");
});
it("stored cloned objects", () => {
@@ -35,11 +34,11 @@ describe("background/infrastructures/memory-storage", () => {
recipe.salt = "20g";
const got = cache.get("recipe");
- expect(got).to.deep.equal({ sugar: "300g", salt: "10g" });
+ expect(got).toEqual({ sugar: "300g", salt: "10g" });
});
it("throws an error with unserializable objects", () => {
const cache = new MemoryStorage();
- expect(() => cache.set("fn", setTimeout)).to.throw();
+ expect(() => cache.set("fn", setTimeout)).toThrow();
});
});
diff --git a/test/background/mock/MockFramePresenter.ts b/test/background/mock/MockFramePresenter.ts
deleted file mode 100644
index d688780..0000000
--- a/test/background/mock/MockFramePresenter.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import FramePresenter from "../../../src/background/presenters/FramePresenter";
-
-export default class MockFramePresenter implements FramePresenter {
- getAllFrameIds(): Promise<number[]> {
- throw new Error("not implemented");
- }
-}
diff --git a/test/background/operators/impls/CancelOperator.test.ts b/test/background/operators/impls/CancelOperator.test.ts
index 915becf..a723f6f 100644
--- a/test/background/operators/impls/CancelOperator.test.ts
+++ b/test/background/operators/impls/CancelOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import CancelOperator from "../../../../src/background/operators/impls/CancelOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockConsoleClient from "../../mock/MockConsoleClient";
@@ -10,15 +9,14 @@ describe("CancelOperator", () => {
const currenTab = await tabPresenter.create("https://example.com/");
const consoleClient = new MockConsoleClient();
- const mock = sinon
- .mock(consoleClient)
- .expects("hide")
- .withArgs(currenTab?.id);
+ const spy = jest
+ .spyOn(consoleClient, "hide")
+ .mockResolvedValueOnce(undefined);
const sut = new CancelOperator(tabPresenter, consoleClient);
await sut.run();
- mock.verify();
+ expect(spy).toBeCalledWith(currenTab?.id);
});
});
});
diff --git a/test/background/operators/impls/CloseTabOperator.test.ts b/test/background/operators/impls/CloseTabOperator.test.ts
index ba9cbfe..f72e118 100644
--- a/test/background/operators/impls/CloseTabOperator.test.ts
+++ b/test/background/operators/impls/CloseTabOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import CloseTabOperator from "../../../../src/background/operators/impls/CloseTabOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
@@ -14,7 +13,7 @@ describe("CloseTabOperator", () => {
await sut.run();
const tabs = await tabPresenter.getAll();
- expect(tabs.map((t) => t.url)).to.deep.equal([
+ expect(tabs.map((t) => t.url)).toEqual([
"https://example.com/1",
"https://example.com/3",
]);
@@ -39,7 +38,7 @@ describe("CloseTabOperator", () => {
await sut.run();
const tabs = await tabPresenter.getAll();
- expect(tabs.map((t) => t.url)).to.deep.equal([
+ expect(tabs.map((t) => t.url)).toEqual([
"https://example.com/1",
"https://example.com/3",
]);
@@ -55,7 +54,7 @@ describe("CloseTabOperator", () => {
await sut.run();
const tab = await tabPresenter.getCurrent();
- expect(tab.url).to.equal("https://example.com/1");
+ expect(tab.url).toEqual("https://example.com/1");
});
});
});
diff --git a/test/background/operators/impls/CloseTabRightOperator.test.ts b/test/background/operators/impls/CloseTabRightOperator.test.ts
index c2a106c..8e2200e 100644
--- a/test/background/operators/impls/CloseTabRightOperator.test.ts
+++ b/test/background/operators/impls/CloseTabRightOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import MockTabPresenter from "../../mock/MockTabPresenter";
import CloseTabRightOperator from "../../../../src/background/operators/impls/CloseTabRightOperator";
@@ -15,7 +14,7 @@ describe("CloseTabRightOperator", () => {
await sut.run();
const tabs = await tabPresenter.getAll();
- expect(tabs.map((t) => t.url)).to.deep.equal([
+ expect(tabs.map((t) => t.url)).toEqual([
"https://example.com/1",
"https://example.com/2",
]);
diff --git a/test/background/operators/impls/CommandOperatorFactoryChain.test.ts b/test/background/operators/impls/CommandOperatorFactoryChain.test.ts
index e481c5a..ce8676a 100644
--- a/test/background/operators/impls/CommandOperatorFactoryChain.test.ts
+++ b/test/background/operators/impls/CommandOperatorFactoryChain.test.ts
@@ -1,5 +1,4 @@
import "reflect-metadata";
-import { expect } from "chai";
import CommandOperatorFactoryChain from "../../../../src/background/operators/impls/CommandOperatorFactoryChain";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockConsoleClient from "../../mock/MockConsoleClient";
@@ -18,25 +17,25 @@ describe("CommandOperatorFactoryChain", () => {
const consoleClient = new MockConsoleClient();
const sut = new CommandOperatorFactoryChain(tabPresenter, consoleClient);
- expect(sut.create({ type: operations.COMMAND_SHOW })).to.be.instanceOf(
+ expect(sut.create({ type: operations.COMMAND_SHOW })).toBeInstanceOf(
ShowCommandOperator
);
expect(
sut.create({ type: operations.COMMAND_SHOW_TABOPEN, alter: true })
- ).to.be.instanceOf(ShowTabOpenCommandOperator);
+ ).toBeInstanceOf(ShowTabOpenCommandOperator);
expect(
sut.create({ type: operations.COMMAND_SHOW_WINOPEN, alter: true })
- ).to.be.instanceOf(ShowWinOpenCommandOperator);
+ ).toBeInstanceOf(ShowWinOpenCommandOperator);
expect(
sut.create({ type: operations.COMMAND_SHOW_BUFFER })
- ).to.be.instanceOf(ShowBufferCommandOperator);
+ ).toBeInstanceOf(ShowBufferCommandOperator);
expect(
sut.create({ type: operations.COMMAND_SHOW_ADDBOOKMARK, alter: true })
- ).to.be.instanceOf(ShowAddBookmarkOperator);
- expect(sut.create({ type: operations.FIND_START })).to.be.instanceOf(
+ ).toBeInstanceOf(ShowAddBookmarkOperator);
+ expect(sut.create({ type: operations.FIND_START })).toBeInstanceOf(
StartFindOperator
);
- expect(sut.create({ type: operations.CANCEL })).to.be.null;
+ expect(sut.create({ type: operations.CANCEL })).toBeNull;
});
});
});
diff --git a/test/background/operators/impls/DuplicateTabOperator.test.ts b/test/background/operators/impls/DuplicateTabOperator.test.ts
index ce2c19d..cbc9e81 100644
--- a/test/background/operators/impls/DuplicateTabOperator.test.ts
+++ b/test/background/operators/impls/DuplicateTabOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import DuplicateTabOperator from "../../../../src/background/operators/impls/DuplicateTabOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
@@ -14,7 +13,7 @@ describe("DuplicateTabOperator", () => {
await sut.run();
const tabs = await tabPresenter.getAll();
- expect(tabs.map((t) => t.url)).to.deep.equal([
+ expect(tabs.map((t) => t.url)).toEqual([
"https://example.com/1",
"https://example.com/2",
"https://example.com/3",
diff --git a/test/background/operators/impls/FindNextOperator.test.ts b/test/background/operators/impls/FindNextOperator.test.ts
index 7509ef4..3bb47f0 100644
--- a/test/background/operators/impls/FindNextOperator.test.ts
+++ b/test/background/operators/impls/FindNextOperator.test.ts
@@ -1,4 +1,3 @@
-import * as sinon from "sinon";
import MockTabPresenter from "../../mock/MockTabPresenter";
import FindNextOperator from "../../../../src/background/operators/impls/FindNextOperator";
import MockFindRepository from "../../mock/MockFindRepository";
@@ -23,155 +22,114 @@ describe("FindNextOperator", () => {
frameRepository
);
+ const findNextSpy = jest.spyOn(findClient, "findNext");
+ const clearSelectionSpy = jest.spyOn(findClient, "clearSelection");
+
let currentTabId: number;
beforeEach(async () => {
- sinon.restore();
-
const currentTab = await tabPresenter.create("https://example.com/", {
active: true,
});
currentTabId = currentTab.id!;
- sinon
- .stub(frameRepository, "getFrameIds")
- .returns(Promise.resolve(frameIds));
+ findNextSpy.mockClear();
+ clearSelectionSpy.mockClear().mockReturnValue(Promise.resolve());
+ jest.spyOn(frameRepository, "getFrameIds").mockResolvedValue(frameIds);
});
describe("#run", () => {
it("shows errors if no previous keywords", async () => {
- sinon
- .stub(findRepository, "getLocalState")
- .returns(Promise.resolve(undefined));
-
- const mock = sinon.mock(consoleClient);
- mock
- .expects("showError")
- .withArgs(currentTabId, "No previous search keywords");
+ jest.spyOn(findRepository, "getLocalState").mockResolvedValue(undefined);
+ const showErrorSpy = jest
+ .spyOn(consoleClient, "showError")
+ .mockReturnValue(Promise.resolve());
await sut.run();
- mock.verify();
+ expect(showErrorSpy).toBeCalledWith(
+ currentTabId,
+ "No previous search keywords"
+ );
});
it("continues a search on the same frame", async () => {
- sinon.stub(findRepository, "getLocalState").returns(
- Promise.resolve({
- keyword,
- frameId: 100,
- })
- );
-
- const mockFindClient = sinon.mock(findClient);
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 100, keyword)
- .returns(Promise.resolve(true));
-
- const mockFindRepository = sinon.mock(findRepository);
- mockFindRepository
- .expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameId: 100 });
+ jest.spyOn(findRepository, "getLocalState").mockResolvedValue({
+ keyword,
+ frameId: 100,
+ });
+ findNextSpy.mockResolvedValue(true);
+ const setLocalStateSpy = jest.spyOn(findRepository, "setLocalState");
await sut.run();
- mockFindRepository.verify();
- mockFindClient.verify();
+ expect(findNextSpy).toBeCalledWith(currentTabId, 100, keyword);
+ expect(setLocalStateSpy).toBeCalledWith(currentTabId, {
+ keyword,
+ frameId: 100,
+ });
});
it("continues a search on next frame", async () => {
- sinon.stub(findRepository, "getLocalState").returns(
- Promise.resolve({
- keyword,
- frameId: 100,
- })
- );
+ jest.spyOn(findRepository, "getLocalState").mockResolvedValue({
+ keyword,
+ frameId: 100,
+ });
- const mockFindClient = sinon.mock(findClient);
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 100, keyword)
- .returns(Promise.resolve(false));
- mockFindClient
- .expects("clearSelection")
- .withArgs(currentTabId, 100)
- .returns(Promise.resolve());
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 101, keyword)
- .returns(Promise.resolve(true));
-
- const mockFindRepository = sinon.mock(findRepository);
- mockFindRepository
- .expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameId: 101 });
+ findNextSpy.mockResolvedValueOnce(false).mockResolvedValueOnce(true);
+ const setLocalStateSpy = jest.spyOn(findRepository, "setLocalState");
await sut.run();
- mockFindRepository.verify();
- mockFindClient.verify();
+ expect(findNextSpy).toBeCalledTimes(2);
+ expect(findNextSpy.mock.calls[0][1]).toEqual(100);
+ expect(findNextSpy.mock.calls[1][1]).toEqual(101);
+ expect(clearSelectionSpy).toBeCalledWith(currentTabId, 100);
+ expect(setLocalStateSpy).toBeCalledWith(currentTabId, {
+ keyword,
+ frameId: 101,
+ });
});
it("exercise a wrap-search", async () => {
- sinon.stub(findRepository, "getLocalState").returns(
- Promise.resolve({
- keyword,
- frameId: 101,
- })
- );
+ jest.spyOn(findRepository, "getLocalState").mockResolvedValue({
+ keyword,
+ frameId: 101,
+ });
- const mockFindClient = sinon.mock(findClient);
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 101, keyword)
- .returns(Promise.resolve(false));
- mockFindClient
- .expects("clearSelection")
- .withArgs(currentTabId, 101)
- .returns(Promise.resolve());
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 0, keyword)
- .returns(Promise.resolve(true));
-
- const mockFindRepository = sinon.mock(findRepository);
- mockFindRepository
- .expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameId: 0 });
+ findNextSpy.mockResolvedValueOnce(false).mockResolvedValueOnce(true);
+ const setLocalStateSpy = jest.spyOn(findRepository, "setLocalState");
await sut.run();
- mockFindRepository.verify();
- mockFindClient.verify();
+ expect(findNextSpy).toBeCalledTimes(2);
+ expect(findNextSpy.mock.calls[0][1]).toEqual(101);
+ expect(findNextSpy.mock.calls[1][1]).toEqual(0);
+ expect(clearSelectionSpy).toBeCalledWith(currentTabId, 101);
+ expect(setLocalStateSpy).toBeCalledWith(currentTabId, {
+ keyword,
+ frameId: 0,
+ });
});
it("starts a search with last keywords", async () => {
- sinon
- .stub(findRepository, "getLocalState")
- .returns(Promise.resolve(undefined));
- sinon
- .stub(findRepository, "getGlobalKeyword")
- .returns(Promise.resolve(keyword));
- sinon.stub(consoleClient, "showInfo").returns(Promise.resolve());
-
- const mockFindClient = sinon.mock(findClient);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 0);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 100);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 101);
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 0, keyword)
- .returns(Promise.resolve(true));
-
- const mockFindRepository = sinon.mock(findRepository);
- mockFindRepository
- .expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameId: 0 });
+ jest.spyOn(findRepository, "getLocalState").mockResolvedValue(undefined);
+ jest.spyOn(findRepository, "getGlobalKeyword").mockResolvedValue(keyword);
+ jest.spyOn(consoleClient, "showInfo").mockReturnValue(Promise.resolve());
+
+ const setLocalStateSpy = jest.spyOn(findRepository, "setLocalState");
await sut.run();
- mockFindRepository.verify();
- mockFindClient.verify();
+ expect(clearSelectionSpy).toBeCalledTimes(3);
+ expect(clearSelectionSpy.mock.calls[0][1]).toEqual(0);
+ expect(clearSelectionSpy.mock.calls[1][1]).toEqual(100);
+ expect(clearSelectionSpy.mock.calls[2][1]).toEqual(101);
+ expect(findNextSpy).toBeCalledWith(currentTabId, 0, keyword);
+ expect(setLocalStateSpy).toBeCalledWith(currentTabId, {
+ keyword,
+ frameId: 0,
+ });
});
});
});
diff --git a/test/background/operators/impls/FindOperatorFactoryChain.ts b/test/background/operators/impls/FindOperatorFactoryChain.ts
index 0fd234f..6b190ed 100644
--- a/test/background/operators/impls/FindOperatorFactoryChain.ts
+++ b/test/background/operators/impls/FindOperatorFactoryChain.ts
@@ -1,5 +1,4 @@
import "reflect-metadata";
-import { expect } from "chai";
import TabOperatorFactoryChain from "../../../../src/background/operators/impls/TabOperatorFactoryChain";
import MockTabPresenter from "../../mock/MockTabPresenter";
import * as operations from "../../../../src/shared/operations";
@@ -12,10 +11,10 @@ describe("FindOperatorFactoryChain", () => {
const tabPresenter = new MockTabPresenter();
const sut = new TabOperatorFactoryChain(tabPresenter);
- expect(sut.create({ type: operations.FIND_NEXT })).to.be.instanceOf(
+ expect(sut.create({ type: operations.FIND_NEXT })).toBeInstanceOf(
FindNextOperator
);
- expect(sut.create({ type: operations.FIND_PREV })).to.be.instanceOf(
+ expect(sut.create({ type: operations.FIND_PREV })).toBeInstanceOf(
FindPrevOperator
);
});
diff --git a/test/background/operators/impls/FindPrevOperator.test.ts b/test/background/operators/impls/FindPrevOperator.test.ts
index 090f815..b563076 100644
--- a/test/background/operators/impls/FindPrevOperator.test.ts
+++ b/test/background/operators/impls/FindPrevOperator.test.ts
@@ -1,4 +1,3 @@
-import * as sinon from "sinon";
import MockTabPresenter from "../../mock/MockTabPresenter";
import FindPrevOperator from "../../../../src/background/operators/impls/FindPrevOperator";
import MockFindRepository from "../../mock/MockFindRepository";
@@ -23,155 +22,113 @@ describe("FindPrevOperator", () => {
frameRepository
);
+ const findPrevSpy = jest.spyOn(findClient, "findPrev");
+ const clearSelectionSpy = jest.spyOn(findClient, "clearSelection");
+
let currentTabId: number;
beforeEach(async () => {
- sinon.restore();
-
const currentTab = await tabPresenter.create("https://example.com/", {
active: true,
});
currentTabId = currentTab.id!;
- sinon
- .stub(frameRepository, "getFrameIds")
- .returns(Promise.resolve(frameIds.slice(0)));
+ findPrevSpy.mockClear();
+ clearSelectionSpy.mockClear().mockReturnValue(Promise.resolve());
+ jest.spyOn(frameRepository, "getFrameIds").mockResolvedValue(frameIds);
});
describe("#run", () => {
it("shows errors if no previous keywords", async () => {
- sinon
- .stub(findRepository, "getLocalState")
- .returns(Promise.resolve(undefined));
-
- const mock = sinon.mock(consoleClient);
- mock
- .expects("showError")
- .withArgs(currentTabId, "No previous search keywords");
+ jest.spyOn(findRepository, "getLocalState").mockResolvedValue(undefined);
+ const showErrorSpy = jest
+ .spyOn(consoleClient, "showError")
+ .mockReturnValue(Promise.resolve());
await sut.run();
- mock.verify();
+ expect(showErrorSpy).toBeCalledWith(
+ currentTabId,
+ "No previous search keywords"
+ );
});
it("continues a search on the same frame", async () => {
- sinon.stub(findRepository, "getLocalState").returns(
- Promise.resolve({
- keyword,
- frameId: 100,
- })
- );
-
- const mockFindClient = sinon.mock(findClient);
- mockFindClient
- .expects("findPrev")
- .withArgs(currentTabId, 100, keyword)
- .returns(Promise.resolve(true));
-
- const mockFindRepository = sinon.mock(findRepository);
- mockFindRepository
- .expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameId: 100 });
+ jest.spyOn(findRepository, "getLocalState").mockResolvedValue({
+ keyword,
+ frameId: 100,
+ });
+ findPrevSpy.mockResolvedValue(true);
+ const setLocalStateSpy = jest.spyOn(findRepository, "setLocalState");
await sut.run();
- mockFindRepository.verify();
- mockFindClient.verify();
+ expect(findPrevSpy).toBeCalledWith(currentTabId, 100, keyword);
+ expect(setLocalStateSpy).toBeCalledWith(currentTabId, {
+ keyword,
+ frameId: 100,
+ });
});
it("continues a search on next frame", async () => {
- sinon.stub(findRepository, "getLocalState").returns(
- Promise.resolve({
- keyword,
- frameId: 100,
- })
- );
-
- const mockFindClient = sinon.mock(findClient);
- mockFindClient
- .expects("findPrev")
- .withArgs(currentTabId, 100, keyword)
- .returns(Promise.resolve(false));
- mockFindClient
- .expects("clearSelection")
- .withArgs(currentTabId, 100)
- .returns(Promise.resolve());
- mockFindClient
- .expects("findPrev")
- .withArgs(currentTabId, 0, keyword)
- .returns(Promise.resolve(true));
-
- const mockFindRepository = sinon.mock(findRepository);
- mockFindRepository
- .expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameId: 0 });
+ jest.spyOn(findRepository, "getLocalState").mockResolvedValue({
+ keyword,
+ frameId: 100,
+ });
+ findPrevSpy.mockResolvedValueOnce(false).mockResolvedValueOnce(true);
+ const setLocalStateSpy = jest.spyOn(findRepository, "setLocalState");
await sut.run();
- mockFindRepository.verify();
- mockFindClient.verify();
+ expect(findPrevSpy).toBeCalledTimes(2);
+ expect(findPrevSpy.mock.calls[0][1]).toEqual(100);
+ expect(findPrevSpy.mock.calls[1][1]).toEqual(0);
+ expect(clearSelectionSpy).toBeCalledWith(currentTabId, 100);
+ expect(setLocalStateSpy).toBeCalledWith(currentTabId, {
+ keyword,
+ frameId: 0,
+ });
});
it("exercise a wrap-search", async () => {
- sinon.stub(findRepository, "getLocalState").returns(
- Promise.resolve({
- keyword,
- frameId: 0,
- })
- );
+ jest.spyOn(findRepository, "getLocalState").mockResolvedValue({
+ keyword,
+ frameId: 0,
+ });
- const mockFindClient = sinon.mock(findClient);
- mockFindClient
- .expects("findPrev")
- .withArgs(currentTabId, 0, keyword)
- .returns(Promise.resolve(false));
- mockFindClient
- .expects("clearSelection")
- .withArgs(currentTabId, 0)
- .returns(Promise.resolve());
- mockFindClient
- .expects("findPrev")
- .withArgs(currentTabId, 101, keyword)
- .returns(Promise.resolve(true));
-
- const mockFindRepository = sinon.mock(findRepository);
- mockFindRepository
- .expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameId: 101 });
+ findPrevSpy.mockResolvedValueOnce(false).mockResolvedValueOnce(true);
+ const setLocalStateSpy = jest.spyOn(findRepository, "setLocalState");
await sut.run();
- mockFindRepository.verify();
- mockFindClient.verify();
+ expect(findPrevSpy).toBeCalledTimes(2);
+ expect(findPrevSpy.mock.calls[0][1]).toEqual(0);
+ expect(findPrevSpy.mock.calls[1][1]).toEqual(101);
+ expect(clearSelectionSpy).toBeCalledWith(currentTabId, 0);
+ expect(setLocalStateSpy).toBeCalledWith(currentTabId, {
+ keyword,
+ frameId: 101,
+ });
});
it("starts a search with last keywords", async () => {
- sinon
- .stub(findRepository, "getLocalState")
- .returns(Promise.resolve(undefined));
- sinon
- .stub(findRepository, "getGlobalKeyword")
- .returns(Promise.resolve(keyword));
- sinon.stub(consoleClient, "showInfo").returns(Promise.resolve());
-
- const mockFindClient = sinon.mock(findClient);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 0);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 100);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 101);
- mockFindClient
- .expects("findPrev")
- .withArgs(currentTabId, 101, keyword)
- .returns(Promise.resolve(true));
-
- const mockFindRepository = sinon.mock(findRepository);
- mockFindRepository
- .expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameId: 101 });
+ jest.spyOn(findRepository, "getLocalState").mockResolvedValue(undefined);
+ jest.spyOn(findRepository, "getGlobalKeyword").mockResolvedValue(keyword);
+ jest.spyOn(consoleClient, "showInfo").mockReturnValue(Promise.resolve());
+
+ const setLocalStateSpy = jest.spyOn(findRepository, "setLocalState");
await sut.run();
- mockFindRepository.verify();
- mockFindClient.verify();
+ expect(clearSelectionSpy).toBeCalledTimes(3);
+ expect(clearSelectionSpy.mock.calls[0][1]).toEqual(101);
+ expect(clearSelectionSpy.mock.calls[1][1]).toEqual(100);
+ expect(clearSelectionSpy.mock.calls[2][1]).toEqual(0);
+ expect(findPrevSpy).toBeCalledWith(currentTabId, 101, keyword);
+ expect(setLocalStateSpy).toBeCalledWith(currentTabId, {
+ keyword,
+ frameId: 101,
+ });
});
});
});
diff --git a/test/background/operators/impls/InternalOpenURLOperator.test.ts b/test/background/operators/impls/InternalOpenURLOperator.test.ts
deleted file mode 100644
index e69de29..0000000
--- a/test/background/operators/impls/InternalOpenURLOperator.test.ts
+++ /dev/null
diff --git a/test/background/operators/impls/InternalOperatorFactoryChain.test.ts b/test/background/operators/impls/InternalOperatorFactoryChain.test.ts
index 09029db..c13ebaf 100644
--- a/test/background/operators/impls/InternalOperatorFactoryChain.test.ts
+++ b/test/background/operators/impls/InternalOperatorFactoryChain.test.ts
@@ -1,5 +1,4 @@
import "reflect-metadata";
-import { expect } from "chai";
import InternalOperatorFactoryChain from "../../../../src/background/operators/impls/InternalOperatorFactoryChain";
import MockWindowPresenter from "../../mock/MockWindowPresenter";
import MockTabPresenter from "../../mock/MockTabPresenter";
@@ -20,7 +19,7 @@ describe("InternalOperatorFactoryChain", () => {
consoleClient
);
- expect(sut.create({ type: operations.CANCEL })).to.be.instanceOf(
+ expect(sut.create({ type: operations.CANCEL })).toBeInstanceOf(
CancelOperator
);
expect(
@@ -30,8 +29,8 @@ describe("InternalOperatorFactoryChain", () => {
newTab: false,
newWindow: false,
})
- ).to.be.instanceOf(InternalOpenURLOperator);
- expect(sut.create({ type: operations.COMMAND_SHOW })).to.be.null;
+ ).toBeInstanceOf(InternalOpenURLOperator);
+ expect(sut.create({ type: operations.COMMAND_SHOW })).toBeNull;
});
});
});
diff --git a/test/background/operators/impls/NavigateHistoryNextOperator.test.ts b/test/background/operators/impls/NavigateHistoryNextOperator.test.ts
index de8f597..8ea925b 100644
--- a/test/background/operators/impls/NavigateHistoryNextOperator.test.ts
+++ b/test/background/operators/impls/NavigateHistoryNextOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import NavigateHistoryNextOperator from "../../../../src/background/operators/impls/NavigateHistoryNextOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockNavigateClient from "../../mock/MockNavigateClient";
@@ -7,10 +6,9 @@ describe("NavigateHistoryNextOperator", () => {
describe("#run", () => {
it("send a message to navigate next in the history", async () => {
const navigateClient = new MockNavigateClient();
- const mock = sinon
- .mock(navigateClient)
- .expects("historyNext")
- .withArgs(1);
+ const historyNextSpy = jest
+ .spyOn(navigateClient, "historyNext")
+ .mockReturnValue(Promise.resolve());
const tabPresenter = new MockTabPresenter();
await tabPresenter.create("https://example.com/1", { active: false });
await tabPresenter.create("https://example.com/2", { active: true });
@@ -19,7 +17,7 @@ describe("NavigateHistoryNextOperator", () => {
await sut.run();
- mock.verify();
+ expect(historyNextSpy).toBeCalledWith(1);
});
});
});
diff --git a/test/background/operators/impls/NavigateHistoryPrevOperator.test.ts b/test/background/operators/impls/NavigateHistoryPrevOperator.test.ts
index 6ebe71e..8221a5c 100644
--- a/test/background/operators/impls/NavigateHistoryPrevOperator.test.ts
+++ b/test/background/operators/impls/NavigateHistoryPrevOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import NavigateHistoryPrevOperator from "../../../../src/background/operators/impls/NavigateHistoryPrevOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockNavigateClient from "../../mock/MockNavigateClient";
@@ -7,10 +6,9 @@ describe("NavigateHistoryPrevOperator", () => {
describe("#run", () => {
it("send a message to navigate previous in the history", async () => {
const navigateClient = new MockNavigateClient();
- const mock = sinon
- .mock(navigateClient)
- .expects("historyPrev")
- .withArgs(1);
+ const historyNextSpy = jest
+ .spyOn(navigateClient, "historyPrev")
+ .mockReturnValue(Promise.resolve());
const tabPresenter = new MockTabPresenter();
await tabPresenter.create("https://example.com/1", { active: false });
await tabPresenter.create("https://example.com/2", { active: true });
@@ -19,7 +17,7 @@ describe("NavigateHistoryPrevOperator", () => {
await sut.run();
- mock.verify();
+ expect(historyNextSpy).toBeCalledWith(1);
});
});
});
diff --git a/test/background/operators/impls/NavigateLinkNextOperator.test.ts b/test/background/operators/impls/NavigateLinkNextOperator.test.ts
index 09c4907..9f19307 100644
--- a/test/background/operators/impls/NavigateLinkNextOperator.test.ts
+++ b/test/background/operators/impls/NavigateLinkNextOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import NavigateLinkNextOperator from "../../../../src/background/operators/impls/NavigateLinkNextOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockNavigateClient from "../../mock/MockNavigateClient";
@@ -7,7 +6,9 @@ describe("NavigateLinkNextOperator", () => {
describe("#run", () => {
it("send a message to navigate next page", async () => {
const navigateClient = new MockNavigateClient();
- const mock = sinon.mock(navigateClient).expects("linkNext").withArgs(1);
+ const linkNextSpy = jest
+ .spyOn(navigateClient, "linkNext")
+ .mockReturnValueOnce(Promise.resolve());
const tabPresenter = new MockTabPresenter();
await tabPresenter.create("https://example.com/1", { active: false });
await tabPresenter.create("https://example.com/2", { active: true });
@@ -16,7 +17,7 @@ describe("NavigateLinkNextOperator", () => {
await sut.run();
- mock.verify();
+ expect(linkNextSpy).toBeCalledWith(1);
});
});
});
diff --git a/test/background/operators/impls/NavigateLinkPrevOperator.test.ts b/test/background/operators/impls/NavigateLinkPrevOperator.test.ts
index 6b7f791..37999bd 100644
--- a/test/background/operators/impls/NavigateLinkPrevOperator.test.ts
+++ b/test/background/operators/impls/NavigateLinkPrevOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import NavigateLinkPrevOperator from "../../../../src/background/operators/impls/NavigateLinkPrevOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockNavigateClient from "../../mock/MockNavigateClient";
@@ -7,7 +6,9 @@ describe("NavigateLinkPrevOperator", () => {
describe("#run", () => {
it("send a message to navigate next page", async () => {
const navigateClient = new MockNavigateClient();
- const mock = sinon.mock(navigateClient).expects("linkPrev").withArgs(1);
+ const linkPrevSpy = jest
+ .spyOn(navigateClient, "linkPrev")
+ .mockReturnValueOnce(Promise.resolve());
const tabPresenter = new MockTabPresenter();
await tabPresenter.create("https://example.com/1", { active: false });
await tabPresenter.create("https://example.com/2", { active: true });
@@ -16,7 +17,7 @@ describe("NavigateLinkPrevOperator", () => {
await sut.run();
- mock.verify();
+ expect(linkPrevSpy).toBeCalledWith(1);
});
});
});
diff --git a/test/background/operators/impls/NavigateOperatorFactoryChain.test.ts b/test/background/operators/impls/NavigateOperatorFactoryChain.test.ts
index dfb5654..ae556f0 100644
--- a/test/background/operators/impls/NavigateOperatorFactoryChain.test.ts
+++ b/test/background/operators/impls/NavigateOperatorFactoryChain.test.ts
@@ -1,5 +1,4 @@
import "reflect-metadata";
-import { expect } from "chai";
import NavigateOperatorFactoryChain from "../../../../src/background/operators/impls/NavigateOperatorFactoryChain";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockNavigateClient from "../../mock/MockNavigateClient";
@@ -28,29 +27,29 @@ describe("NavigateOperatorFactoryChain", () => {
expect(
sut.create({ type: operations.NAVIGATE_HISTORY_PREV })
- ).to.be.instanceOf(NavigateHistoryPrevOperator);
+ ).toBeInstanceOf(NavigateHistoryPrevOperator);
expect(
sut.create({ type: operations.NAVIGATE_HISTORY_NEXT })
- ).to.be.instanceOf(NavigateHistoryNextOperator);
+ ).toBeInstanceOf(NavigateHistoryNextOperator);
expect(
sut.create({ type: operations.NAVIGATE_LINK_PREV })
- ).to.be.instanceOf(NavigateLinkPrevOperator);
+ ).toBeInstanceOf(NavigateLinkPrevOperator);
expect(
sut.create({ type: operations.NAVIGATE_LINK_NEXT })
- ).to.be.instanceOf(NavigateLinkNextOperator);
- expect(sut.create({ type: operations.NAVIGATE_PARENT })).to.be.instanceOf(
+ ).toBeInstanceOf(NavigateLinkNextOperator);
+ expect(sut.create({ type: operations.NAVIGATE_PARENT })).toBeInstanceOf(
NavigateParentOperator
);
- expect(sut.create({ type: operations.NAVIGATE_ROOT })).to.be.instanceOf(
+ expect(sut.create({ type: operations.NAVIGATE_ROOT })).toBeInstanceOf(
NavigateRootOperator
);
- expect(sut.create({ type: operations.PAGE_SOURCE })).to.be.instanceOf(
+ expect(sut.create({ type: operations.PAGE_SOURCE })).toBeInstanceOf(
OpenSourceOperator
);
expect(
sut.create({ type: operations.PAGE_HOME, newTab: false })
- ).to.be.instanceOf(OpenHomeOperator);
- expect(sut.create({ type: operations.CANCEL })).to.be.null;
+ ).toBeInstanceOf(OpenHomeOperator);
+ expect(sut.create({ type: operations.CANCEL })).toBeNull;
});
});
});
diff --git a/test/background/operators/impls/NavigateParentOperator.test.ts b/test/background/operators/impls/NavigateParentOperator.test.ts
index cc57f17..48c14dd 100644
--- a/test/background/operators/impls/NavigateParentOperator.test.ts
+++ b/test/background/operators/impls/NavigateParentOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import MockTabPresenter from "../../mock/MockTabPresenter";
import NavigateParentOperator from "../../../../src/background/operators/impls/NavigateParentOperator";
@@ -14,7 +13,7 @@ describe("NavigateParentOperator", () => {
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.be.equal("https://example.com/fruits/yellow/");
+ expect(url).toEqual("https://example.com/fruits/yellow/");
});
it("opens a parent directory of the directoryin the URL", async () => {
@@ -25,7 +24,7 @@ describe("NavigateParentOperator", () => {
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.be.equal("https://example.com/fruits/");
+ expect(url).toEqual("https://example.com/fruits/");
});
it("removes a hash in the URL", async () => {
@@ -36,7 +35,7 @@ describe("NavigateParentOperator", () => {
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.be.equal("https://example.com/fruits/yellow/");
+ expect(url).toEqual("https://example.com/fruits/yellow/");
});
it("removes query parameters in the URL", async () => {
@@ -47,7 +46,7 @@ describe("NavigateParentOperator", () => {
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.be.equal("https://example.com/search");
+ expect(url).toEqual("https://example.com/search");
});
});
});
diff --git a/test/background/operators/impls/NavigateRootOperator.test.ts b/test/background/operators/impls/NavigateRootOperator.test.ts
index bbe574c..379ce44 100644
--- a/test/background/operators/impls/NavigateRootOperator.test.ts
+++ b/test/background/operators/impls/NavigateRootOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import NavigateRootOperator from "../../../../src/background/operators/impls/NavigateRootOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
@@ -12,7 +11,7 @@ describe("NavigateRootOperator", () => {
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.be.equal("https://example.com");
+ expect(url).toEqual("https://example.com");
});
});
});
diff --git a/test/background/operators/impls/OpenHomeOperator.test.ts b/test/background/operators/impls/OpenHomeOperator.test.ts
index 3c9288f..580aa49 100644
--- a/test/background/operators/impls/OpenHomeOperator.test.ts
+++ b/test/background/operators/impls/OpenHomeOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import OpenHomeOperator from "../../../../src/background/operators/impls/OpenHomeOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockBrowserSettingRepository from "../../mock/MockBrowserSettingRepository";
@@ -20,7 +19,7 @@ describe("OpenHomeOperator", () => {
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.be.equal("https://example.net/");
+ expect(url).toEqual("https://example.net/");
});
it("opens a home page of the browser into a new tab", async () => {
@@ -38,10 +37,7 @@ describe("OpenHomeOperator", () => {
await sut.run();
const urls = (await tabPresenter.getAll()).map((t) => t.url);
- expect(urls).to.be.deep.equal([
- "https://example.com/",
- "https://example.net/",
- ]);
+ expect(urls).toEqual(["https://example.com/", "https://example.net/"]);
});
it("opens home pages of the browser", async () => {
@@ -60,7 +56,7 @@ describe("OpenHomeOperator", () => {
await sut.run();
const urls = (await tabPresenter.getAll()).map((t) => t.url);
- expect(urls).to.be.deep.equal([
+ expect(urls).toEqual([
"https://example.com/",
"https://example.net/",
"https://example.org/",
diff --git a/test/background/operators/impls/OpenSourceOperator.test.ts b/test/background/operators/impls/OpenSourceOperator.test.ts
index 541032b..4d9423c 100644
--- a/test/background/operators/impls/OpenSourceOperator.test.ts
+++ b/test/background/operators/impls/OpenSourceOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import OpenSourceOperator from "../../../../src/background/operators/impls/OpenSourceOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
@@ -12,7 +11,7 @@ describe("OpenSourceOperator", () => {
await sut.run();
const urls = (await tabPresenter.getAll()).map((t) => t.url);
- expect(urls).to.be.deep.equal([
+ expect(urls).toEqual([
"https://example.com/",
"view-source:https://example.com/",
]);
diff --git a/test/background/operators/impls/PinTabOperator.test.ts b/test/background/operators/impls/PinTabOperator.test.ts
index 0c940b6..69082f2 100644
--- a/test/background/operators/impls/PinTabOperator.test.ts
+++ b/test/background/operators/impls/PinTabOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import PinTabOperator from "../../../../src/background/operators/impls/PinTabOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
@@ -19,7 +18,7 @@ describe("PinTabOperator", () => {
await sut.run();
const pins = (await tabPresenter.getAll()).map((t) => t.pinned);
- expect(pins).to.deep.equal([true, false]);
+ expect(pins).toEqual([true, false]);
});
});
});
diff --git a/test/background/operators/impls/ReloadTabOperator.test.ts b/test/background/operators/impls/ReloadTabOperator.test.ts
index e87782b..0cedf3e 100644
--- a/test/background/operators/impls/ReloadTabOperator.test.ts
+++ b/test/background/operators/impls/ReloadTabOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import ReloadTabOperator from "../../../../src/background/operators/impls/ReloadTabOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
@@ -8,27 +7,28 @@ describe("ReloadTabOperator", () => {
const tabPresenter = new MockTabPresenter();
await tabPresenter.create("https://example.com/", { active: true });
await tabPresenter.create("https://example.com/", { active: false });
- const mock = sinon.mock(tabPresenter).expects("reload").withArgs(0, true);
+ const reloadSpy = jest
+ .spyOn(tabPresenter, "reload")
+ .mockReturnValue(Promise.resolve());
const sut = new ReloadTabOperator(tabPresenter, true);
await sut.run();
- mock.verify();
+ expect(reloadSpy).toBeCalledWith(0, true);
});
it("reloads the current tab without cache", async () => {
const tabPresenter = new MockTabPresenter();
await tabPresenter.create("https://example.com/", { active: true });
await tabPresenter.create("https://example.com/", { active: false });
- const mock = sinon
- .mock(tabPresenter)
- .expects("reload")
- .withArgs(0, false);
+ const reloadSpy = jest
+ .spyOn(tabPresenter, "reload")
+ .mockReturnValue(Promise.resolve());
const sut = new ReloadTabOperator(tabPresenter, false);
await sut.run();
- mock.verify();
+ expect(reloadSpy).toBeCalledWith(0, false);
});
});
});
diff --git a/test/background/operators/impls/ReopenTabOperator.test.ts b/test/background/operators/impls/ReopenTabOperator.test.ts
index 43b1575..5581f9a 100644
--- a/test/background/operators/impls/ReopenTabOperator.test.ts
+++ b/test/background/operators/impls/ReopenTabOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import ReopenTabOperator from "../../../../src/background/operators/impls/ReopenTabOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
@@ -6,12 +5,14 @@ describe("ReopenTabOperator", () => {
describe("#run", () => {
it("reopens closed tabs", async () => {
const tabPresenter = new MockTabPresenter();
- const mock = sinon.mock(tabPresenter).expects("reopen");
+ const reopenSpy = jest
+ .spyOn(tabPresenter, "reopen")
+ .mockReturnValue(Promise.resolve());
const sut = new ReopenTabOperator(tabPresenter);
await sut.run();
- mock.verify();
+ expect(reopenSpy).toBeCalled();
});
});
});
diff --git a/test/background/operators/impls/RepeatLastOperator.test.ts b/test/background/operators/impls/RepeatLastOperator.test.ts
index 57f1227..fc37615 100644
--- a/test/background/operators/impls/RepeatLastOperator.test.ts
+++ b/test/background/operators/impls/RepeatLastOperator.test.ts
@@ -3,7 +3,6 @@ import MockRepeatRepository from "../../mock/MockRepeatRepository";
import OperatorFactory from "../../../../src/background/operators/OperatorFactory";
import * as operations from "../../../../src/shared/operations";
import Operator from "../../../../src/background/operators/Operator";
-import sinon from "sinon";
class MockOperatorFactory implements OperatorFactory {
create(_op: operations.Operation): Operator {
@@ -21,36 +20,34 @@ describe("RepeatLastOperator", () => {
describe("#run", () => {
it("repeat last operation", async () => {
const operator = new MockOperator();
- const operatorMock = sinon.mock(operator).expects("run").once();
+ const runSpy = jest
+ .spyOn(operator, "run")
+ .mockReturnValue(Promise.resolve());
+
const repeatRepository = new MockRepeatRepository();
repeatRepository.setLastOperation({ type: operations.CANCEL });
const operatorFactory = new MockOperatorFactory();
- const operatorFactoryMock = sinon
- .mock(operatorFactory)
- .expects("create")
- .withArgs({ type: operations.CANCEL });
- operatorFactoryMock.returns(operator);
+ const createSpy = jest
+ .spyOn(operatorFactory, "create")
+ .mockReturnValue(operator);
const sut = new RepeatLastOperator(repeatRepository, operatorFactory);
await sut.run();
- operatorFactoryMock.verify();
- operatorMock.verify();
+ expect(runSpy).toBeCalledTimes(1);
+ expect(createSpy).toBeCalledWith({ type: operations.CANCEL });
});
it("does nothing if no last operations", async () => {
const repeatRepository = new MockRepeatRepository();
const operatorFactory = new MockOperatorFactory();
- const operatorFactoryMock = sinon
- .mock(operatorFactory)
- .expects("create")
- .never();
+ const createSpy = jest.spyOn(operatorFactory, "create");
const sut = new RepeatLastOperator(repeatRepository, operatorFactory);
await sut.run();
- operatorFactoryMock.verify();
+ expect(createSpy).not.toBeCalled();
});
});
});
diff --git a/test/background/operators/impls/RepeatOperatorFactoryChain.test.ts b/test/background/operators/impls/RepeatOperatorFactoryChain.test.ts
index e12d788..ec5e000 100644
--- a/test/background/operators/impls/RepeatOperatorFactoryChain.test.ts
+++ b/test/background/operators/impls/RepeatOperatorFactoryChain.test.ts
@@ -1,5 +1,4 @@
import "reflect-metadata";
-import { expect } from "chai";
import RepeatOperatorFactoryChain from "../../../../src/background/operators/impls/RepeatOperatorFactoryChain";
import RepeatLastOperator from "../../../../src/background/operators/impls/RepeatLastOperator";
import OperatorFactory from "../../../../src/background/operators/OperatorFactory";
@@ -23,10 +22,10 @@ describe("RepeatOperatorFactoryChain", () => {
operatorFactory
);
- expect(sut.create({ type: operations.REPEAT_LAST })).to.be.instanceOf(
+ expect(sut.create({ type: operations.REPEAT_LAST })).toBeInstanceOf(
RepeatLastOperator
);
- expect(sut.create({ type: operations.CANCEL })).to.be.null;
+ expect(sut.create({ type: operations.CANCEL })).toBeNull;
});
});
});
diff --git a/test/background/operators/impls/ResetZoomOperator.test.ts b/test/background/operators/impls/ResetZoomOperator.test.ts
index 68cda05..40c56d9 100644
--- a/test/background/operators/impls/ResetZoomOperator.test.ts
+++ b/test/background/operators/impls/ResetZoomOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import ResetZoomOperator from "../../../../src/background/operators/impls/ResetZoomOperator";
import MockZoomPresenter from "../../mock/MockZoomPresenter";
@@ -6,12 +5,14 @@ describe("ResetZoomOperator", () => {
describe("#run", () => {
it("resets zoom on the tab", async () => {
const zoomPresenter = new MockZoomPresenter();
- const mock = sinon.mock(zoomPresenter).expects("resetZoom").once();
+ const resetZoomSpy = jest
+ .spyOn(zoomPresenter, "resetZoom")
+ .mockReturnValue(Promise.resolve());
const sut = new ResetZoomOperator(zoomPresenter);
await sut.run();
- mock.verify();
+ expect(resetZoomSpy).toBeCalled();
});
});
});
diff --git a/test/background/operators/impls/SelectFirstTabOperator.test.ts b/test/background/operators/impls/SelectFirstTabOperator.test.ts
index a3f1d7e..ae8a42e 100644
--- a/test/background/operators/impls/SelectFirstTabOperator.test.ts
+++ b/test/background/operators/impls/SelectFirstTabOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import SelectFirstTabOperator from "../../../../src/background/operators/impls/SelectFirstTabOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
@@ -14,7 +13,7 @@ describe("SelectFirstTabOperator", () => {
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.equal("https://example.com/1");
+ expect(url).toEqual("https://example.com/1");
});
});
});
diff --git a/test/background/operators/impls/SelectLastTabOperator.test.ts b/test/background/operators/impls/SelectLastTabOperator.test.ts
index b8cf5c4..63668b1 100644
--- a/test/background/operators/impls/SelectLastTabOperator.test.ts
+++ b/test/background/operators/impls/SelectLastTabOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import SelectLastTabOperator from "../../../../src/background/operators/impls/SelectLastTabOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
@@ -14,7 +13,7 @@ describe("SelectLastTabOperator", () => {
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.equal("https://example.com/3");
+ expect(url).toEqual("https://example.com/3");
});
});
});
diff --git a/test/background/operators/impls/SelectPreviousSelectedTabOperator.test.ts b/test/background/operators/impls/SelectPreviousSelectedTabOperator.test.ts
index 5e6cc73..7872b2f 100644
--- a/test/background/operators/impls/SelectPreviousSelectedTabOperator.test.ts
+++ b/test/background/operators/impls/SelectPreviousSelectedTabOperator.test.ts
@@ -1,5 +1,3 @@
-import { expect } from "chai";
-import sinon from "sinon";
import MockTabPresenter from "../../mock/MockTabPresenter";
import SelectPreviousSelectedTabOperator from "../../../../src/background/operators/impls/SelectPreviousSelectedTabOperator";
@@ -10,13 +8,13 @@ describe("SelectPreviousSelectedTabOperator", () => {
await tabPresenter.create("https://example.com/1", { active: false });
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
- sinon.stub(tabPresenter, "getLastSelectedId").returns(Promise.resolve(0));
+ jest.spyOn(tabPresenter, "getLastSelectedId").mockResolvedValue(0);
const sut = new SelectPreviousSelectedTabOperator(tabPresenter);
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.equal("https://example.com/1");
+ expect(url).toEqual("https://example.com/1");
});
it("do nothing if no last-selected tabs", async () => {
@@ -24,15 +22,15 @@ describe("SelectPreviousSelectedTabOperator", () => {
await tabPresenter.create("https://example.com/1", { active: false });
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
- sinon
- .stub(tabPresenter, "getLastSelectedId")
- .returns(Promise.resolve(undefined));
- const mock = sinon.mock(tabPresenter).expects("select").never();
+ jest
+ .spyOn(tabPresenter, "getLastSelectedId")
+ .mockResolvedValue(undefined);
+ const selectSpy = jest.spyOn(tabPresenter, "select");
const sut = new SelectPreviousSelectedTabOperator(tabPresenter);
await sut.run();
- mock.verify();
+ expect(selectSpy).not.toBeCalled();
});
});
});
diff --git a/test/background/operators/impls/SelectTabNextOperator.test.ts b/test/background/operators/impls/SelectTabNextOperator.test.ts
index 5952d92..cc845e5 100644
--- a/test/background/operators/impls/SelectTabNextOperator.test.ts
+++ b/test/background/operators/impls/SelectTabNextOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import MockTabPresenter from "../../mock/MockTabPresenter";
import SelectTabNextOperator from "../../../../src/background/operators/impls/SelectTabNextOperator";
@@ -14,7 +13,7 @@ describe("SelectTabNextOperator", () => {
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.equal("https://example.com/3");
+ expect(url).toEqual("https://example.com/3");
});
});
@@ -29,7 +28,7 @@ describe("SelectTabNextOperator", () => {
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.equal("https://example.com/1");
+ expect(url).toEqual("https://example.com/1");
});
});
});
diff --git a/test/background/operators/impls/SelectTabPrevOperator.test.ts b/test/background/operators/impls/SelectTabPrevOperator.test.ts
index c9092fa..41df299 100644
--- a/test/background/operators/impls/SelectTabPrevOperator.test.ts
+++ b/test/background/operators/impls/SelectTabPrevOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import MockTabPresenter from "../../mock/MockTabPresenter";
import SelectTabPrevOperator from "../../../../src/background/operators/impls/SelectTabPrevOperator";
@@ -14,7 +13,7 @@ describe("SelectTabPrevOperator", () => {
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.equal("https://example.com/1");
+ expect(url).toEqual("https://example.com/1");
});
});
@@ -29,7 +28,7 @@ describe("SelectTabPrevOperator", () => {
await sut.run();
const url = (await tabPresenter.getCurrent()).url;
- expect(url).to.equal("https://example.com/3");
+ expect(url).toEqual("https://example.com/3");
});
});
});
diff --git a/test/background/operators/impls/ShowAddBookmarkOperator.test.ts b/test/background/operators/impls/ShowAddBookmarkOperator.test.ts
index 1e083c2..aab7451 100644
--- a/test/background/operators/impls/ShowAddBookmarkOperator.test.ts
+++ b/test/background/operators/impls/ShowAddBookmarkOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import ShowAddBookmarkOperator from "../../../../src/background/operators/impls/ShowAddBookmarkOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockConsoleClient from "../../mock/MockConsoleClient";
@@ -11,10 +10,9 @@ describe("ShowAddBookmarkOperator", () => {
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
const consoleClient = new MockConsoleClient();
- const mock = sinon
- .mock(consoleClient)
- .expects("showCommand")
- .withArgs(1, "addbookmark ");
+ const showCommandSpy = jest
+ .spyOn(consoleClient, "showCommand")
+ .mockReturnValue(Promise.resolve());
const sut = new ShowAddBookmarkOperator(
tabPresenter,
@@ -23,7 +21,7 @@ describe("ShowAddBookmarkOperator", () => {
);
await sut.run();
- mock.verify();
+ expect(showCommandSpy).toBeCalledWith(1, "addbookmark ");
});
it("show command with addbookmark command and an URL of the current tab", async () => {
@@ -32,10 +30,9 @@ describe("ShowAddBookmarkOperator", () => {
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
const consoleClient = new MockConsoleClient();
- const mock = sinon
- .mock(consoleClient)
- .expects("showCommand")
- .withArgs(1, "addbookmark welcome, world");
+ const showCommandSpy = jest
+ .spyOn(consoleClient, "showCommand")
+ .mockReturnValue(Promise.resolve());
const sut = new ShowAddBookmarkOperator(
tabPresenter,
@@ -44,7 +41,7 @@ describe("ShowAddBookmarkOperator", () => {
);
await sut.run();
- mock.verify();
+ expect(showCommandSpy).toBeCalledWith(1, "addbookmark welcome, world");
});
});
});
diff --git a/test/background/operators/impls/ShowBufferCommandOperator.test.ts b/test/background/operators/impls/ShowBufferCommandOperator.test.ts
index 91455b3..fbd1429 100644
--- a/test/background/operators/impls/ShowBufferCommandOperator.test.ts
+++ b/test/background/operators/impls/ShowBufferCommandOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import ShowBufferCommandOperator from "../../../../src/background/operators/impls/ShowBufferCommandOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockConsoleClient from "../../mock/MockConsoleClient";
@@ -11,15 +10,14 @@ describe("ShowBufferCommandOperator", () => {
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
const consoleClient = new MockConsoleClient();
- const mock = sinon
- .mock(consoleClient)
- .expects("showCommand")
- .withArgs(1, "buffer ");
+ const showCommandSpy = jest
+ .spyOn(consoleClient, "showCommand")
+ .mockReturnValue(Promise.resolve());
const sut = new ShowBufferCommandOperator(tabPresenter, consoleClient);
await sut.run();
- mock.verify();
+ expect(showCommandSpy).toBeCalledWith(1, "buffer ");
});
});
});
diff --git a/test/background/operators/impls/ShowCommandOperator.test.ts b/test/background/operators/impls/ShowCommandOperator.test.ts
index 83b028c..c07176d 100644
--- a/test/background/operators/impls/ShowCommandOperator.test.ts
+++ b/test/background/operators/impls/ShowCommandOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import ShowCommandOperator from "../../../../src/background/operators/impls/ShowCommandOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockConsoleClient from "../../mock/MockConsoleClient";
@@ -11,15 +10,14 @@ describe("ShowCommandOperator", () => {
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
const consoleClient = new MockConsoleClient();
- const mock = sinon
- .mock(consoleClient)
- .expects("showCommand")
- .withArgs(1, "");
+ const showCommandSpy = jest
+ .spyOn(consoleClient, "showCommand")
+ .mockReturnValue(Promise.resolve());
const sut = new ShowCommandOperator(tabPresenter, consoleClient);
await sut.run();
- mock.verify();
+ expect(showCommandSpy).toBeCalledWith(1, "");
});
});
});
diff --git a/test/background/operators/impls/ShowOpenCommandOperator.test.ts b/test/background/operators/impls/ShowOpenCommandOperator.test.ts
index 2c2105a..b4f631a 100644
--- a/test/background/operators/impls/ShowOpenCommandOperator.test.ts
+++ b/test/background/operators/impls/ShowOpenCommandOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import ShowOpenCommandOperator from "../../../../src/background/operators/impls/ShowOpenCommandOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockConsoleClient from "../../mock/MockConsoleClient";
@@ -11,10 +10,9 @@ describe("ShowOpenCommandOperator", () => {
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
const consoleClient = new MockConsoleClient();
- const mock = sinon
- .mock(consoleClient)
- .expects("showCommand")
- .withArgs(1, "open ");
+ const showCommandSpy = jest
+ .spyOn(consoleClient, "showCommand")
+ .mockReturnValue(Promise.resolve());
const sut = new ShowOpenCommandOperator(
tabPresenter,
@@ -23,7 +21,7 @@ describe("ShowOpenCommandOperator", () => {
);
await sut.run();
- mock.verify();
+ expect(showCommandSpy).toBeCalledWith(1, "open ");
});
it("show command with open command and an URL of the current tab", async () => {
@@ -32,10 +30,9 @@ describe("ShowOpenCommandOperator", () => {
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
const consoleClient = new MockConsoleClient();
- const mock = sinon
- .mock(consoleClient)
- .expects("showCommand")
- .withArgs(1, "open https://example.com/2");
+ const showCommandSpy = jest
+ .spyOn(consoleClient, "showCommand")
+ .mockReturnValue(Promise.resolve());
const sut = new ShowOpenCommandOperator(
tabPresenter,
@@ -44,7 +41,7 @@ describe("ShowOpenCommandOperator", () => {
);
await sut.run();
- mock.verify();
+ expect(showCommandSpy).toBeCalledWith(1, "open https://example.com/2");
});
});
});
diff --git a/test/background/operators/impls/ShowTabOpenCommandOperator.test.ts b/test/background/operators/impls/ShowTabOpenCommandOperator.test.ts
index e291d05..1896a08 100644
--- a/test/background/operators/impls/ShowTabOpenCommandOperator.test.ts
+++ b/test/background/operators/impls/ShowTabOpenCommandOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import ShowTabOpenCommandOperator from "../../../../src/background/operators/impls/ShowTabOpenCommandOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockConsoleClient from "../../mock/MockConsoleClient";
@@ -11,10 +10,9 @@ describe("ShowTabOpenCommandOperator", () => {
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
const consoleClient = new MockConsoleClient();
- const mock = sinon
- .mock(consoleClient)
- .expects("showCommand")
- .withArgs(1, "tabopen ");
+ const showCommandSpy = jest
+ .spyOn(consoleClient, "showCommand")
+ .mockReturnValue(Promise.resolve());
const sut = new ShowTabOpenCommandOperator(
tabPresenter,
@@ -23,7 +21,7 @@ describe("ShowTabOpenCommandOperator", () => {
);
await sut.run();
- mock.verify();
+ expect(showCommandSpy).toBeCalledWith(1, "tabopen ");
});
it("show command with tabopen command and an URL of the current tab", async () => {
@@ -32,10 +30,9 @@ describe("ShowTabOpenCommandOperator", () => {
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
const consoleClient = new MockConsoleClient();
- const mock = sinon
- .mock(consoleClient)
- .expects("showCommand")
- .withArgs(1, "tabopen https://example.com/2");
+ const showCommandSpy = jest
+ .spyOn(consoleClient, "showCommand")
+ .mockReturnValue(Promise.resolve());
const sut = new ShowTabOpenCommandOperator(
tabPresenter,
@@ -44,7 +41,7 @@ describe("ShowTabOpenCommandOperator", () => {
);
await sut.run();
- mock.verify();
+ expect(showCommandSpy).toBeCalledWith(1, "tabopen https://example.com/2");
});
});
});
diff --git a/test/background/operators/impls/ShowWinOpenCommandOperator.test.ts b/test/background/operators/impls/ShowWinOpenCommandOperator.test.ts
index c81a2d4..ce2a5b8 100644
--- a/test/background/operators/impls/ShowWinOpenCommandOperator.test.ts
+++ b/test/background/operators/impls/ShowWinOpenCommandOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import ShowWinOpenCommandOperator from "../../../../src/background/operators/impls/ShowWinOpenCommandOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockConsoleClient from "../../mock/MockConsoleClient";
@@ -11,10 +10,9 @@ describe("ShowWinOpenCommandOperator", () => {
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
const consoleClient = new MockConsoleClient();
- const mock = sinon
- .mock(consoleClient)
- .expects("showCommand")
- .withArgs(1, "winopen ");
+ const showCommandSpy = jest
+ .spyOn(consoleClient, "showCommand")
+ .mockReturnValue(Promise.resolve());
const sut = new ShowWinOpenCommandOperator(
tabPresenter,
@@ -23,7 +21,7 @@ describe("ShowWinOpenCommandOperator", () => {
);
await sut.run();
- mock.verify();
+ expect(showCommandSpy).toBeCalledWith(1, "winopen ");
});
it("show command with winopen command and an URL of the current tab", async () => {
@@ -32,10 +30,9 @@ describe("ShowWinOpenCommandOperator", () => {
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
const consoleClient = new MockConsoleClient();
- const mock = sinon
- .mock(consoleClient)
- .expects("showCommand")
- .withArgs(1, "winopen https://example.com/2");
+ const showCommandSpy = jest
+ .spyOn(consoleClient, "showCommand")
+ .mockReturnValue(Promise.resolve());
const sut = new ShowWinOpenCommandOperator(
tabPresenter,
@@ -44,7 +41,7 @@ describe("ShowWinOpenCommandOperator", () => {
);
await sut.run();
- mock.verify();
+ expect(showCommandSpy).toBeCalledWith(1, "winopen https://example.com/2");
});
});
});
diff --git a/test/background/operators/impls/StartFindOperator.test.ts b/test/background/operators/impls/StartFindOperator.test.ts
index 7764520..23ebda8 100644
--- a/test/background/operators/impls/StartFindOperator.test.ts
+++ b/test/background/operators/impls/StartFindOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import StartFindOperator from "../../../../src/background/operators/impls/StartFindOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
import MockConsoleClient from "../../mock/MockConsoleClient";
@@ -11,12 +10,14 @@ describe("StartFindOperator", () => {
await tabPresenter.create("https://example.com/2", { active: true });
await tabPresenter.create("https://example.com/3", { active: false });
const consoleClient = new MockConsoleClient();
- const mock = sinon.mock(consoleClient).expects("showFind").withArgs(1);
+ const showFindSpy = jest
+ .spyOn(consoleClient, "showFind")
+ .mockReturnValue(Promise.resolve());
const sut = new StartFindOperator(tabPresenter, consoleClient);
await sut.run();
- mock.verify();
+ expect(showFindSpy).toBeCalledWith(1);
});
});
});
diff --git a/test/background/operators/impls/TabOperatorFactoryChain.test.ts b/test/background/operators/impls/TabOperatorFactoryChain.test.ts
index a777973..57e6321 100644
--- a/test/background/operators/impls/TabOperatorFactoryChain.test.ts
+++ b/test/background/operators/impls/TabOperatorFactoryChain.test.ts
@@ -1,5 +1,4 @@
import "reflect-metadata";
-import { expect } from "chai";
import TabOperatorFactoryChain from "../../../../src/background/operators/impls/TabOperatorFactoryChain";
import MockTabPresenter from "../../mock/MockTabPresenter";
import DuplicateTabOperator from "../../../../src/background/operators/impls/DuplicateTabOperator";
@@ -23,49 +22,49 @@ describe("TabOperatorFactoryChain", () => {
const tabPresenter = new MockTabPresenter();
const sut = new TabOperatorFactoryChain(tabPresenter);
- expect(sut.create({ type: operations.TAB_CLOSE })).to.be.instanceOf(
+ expect(sut.create({ type: operations.TAB_CLOSE })).toBeInstanceOf(
CloseTabOperator
);
- expect(sut.create({ type: operations.TAB_CLOSE_RIGHT })).to.be.instanceOf(
+ expect(sut.create({ type: operations.TAB_CLOSE_RIGHT })).toBeInstanceOf(
CloseTabRightOperator
);
- expect(sut.create({ type: operations.TAB_CLOSE_FORCE })).to.be.instanceOf(
+ expect(sut.create({ type: operations.TAB_CLOSE_FORCE })).toBeInstanceOf(
CloseTabOperator
);
- expect(sut.create({ type: operations.TAB_REOPEN })).to.be.instanceOf(
+ expect(sut.create({ type: operations.TAB_REOPEN })).toBeInstanceOf(
ReopenTabOperator
);
- expect(sut.create({ type: operations.TAB_PREV })).to.be.instanceOf(
+ expect(sut.create({ type: operations.TAB_PREV })).toBeInstanceOf(
SelectTabPrevOperator
);
- expect(sut.create({ type: operations.TAB_NEXT })).to.be.instanceOf(
+ expect(sut.create({ type: operations.TAB_NEXT })).toBeInstanceOf(
SelectTabNextOperator
);
- expect(sut.create({ type: operations.TAB_FIRST })).to.be.instanceOf(
+ expect(sut.create({ type: operations.TAB_FIRST })).toBeInstanceOf(
SelectFirstTabOperator
);
- expect(sut.create({ type: operations.TAB_LAST })).to.be.instanceOf(
+ expect(sut.create({ type: operations.TAB_LAST })).toBeInstanceOf(
SelectLastTabOperator
);
- expect(sut.create({ type: operations.TAB_PREV_SEL })).to.be.instanceOf(
+ expect(sut.create({ type: operations.TAB_PREV_SEL })).toBeInstanceOf(
SelectPreviousSelectedTabOperator
);
expect(
sut.create({ type: operations.TAB_RELOAD, cache: false })
- ).to.be.instanceOf(ReloadTabOperator);
- expect(sut.create({ type: operations.TAB_PIN })).to.be.instanceOf(
+ ).toBeInstanceOf(ReloadTabOperator);
+ expect(sut.create({ type: operations.TAB_PIN })).toBeInstanceOf(
PinTabOperator
);
- expect(sut.create({ type: operations.TAB_UNPIN })).to.be.instanceOf(
+ expect(sut.create({ type: operations.TAB_UNPIN })).toBeInstanceOf(
UnpinTabOperator
);
- expect(
- sut.create({ type: operations.TAB_TOGGLE_PINNED })
- ).to.be.instanceOf(TogglePinnedTabOperator);
- expect(sut.create({ type: operations.TAB_DUPLICATE })).to.be.instanceOf(
+ expect(sut.create({ type: operations.TAB_TOGGLE_PINNED })).toBeInstanceOf(
+ TogglePinnedTabOperator
+ );
+ expect(sut.create({ type: operations.TAB_DUPLICATE })).toBeInstanceOf(
DuplicateTabOperator
);
- expect(sut.create({ type: operations.CANCEL })).to.be.null;
+ expect(sut.create({ type: operations.CANCEL })).toBeNull;
});
});
});
diff --git a/test/background/operators/impls/TogglePinnedTabOperator.test.ts b/test/background/operators/impls/TogglePinnedTabOperator.test.ts
index f155f83..fbd6c39 100644
--- a/test/background/operators/impls/TogglePinnedTabOperator.test.ts
+++ b/test/background/operators/impls/TogglePinnedTabOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import TogglePinnedTabOperator from "../../../../src/background/operators/impls/TogglePinnedTabOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
@@ -17,13 +16,13 @@ describe("TogglePinnedTabOperator", () => {
const sut = new TogglePinnedTabOperator(tabPresenter);
await sut.run();
- expect((await tabPresenter.getAll()).map((t) => t.pinned)).to.deep.equal([
+ expect((await tabPresenter.getAll()).map((t) => t.pinned)).toEqual([
true,
false,
]);
await sut.run();
- expect((await tabPresenter.getAll()).map((t) => t.pinned)).to.deep.equal([
+ expect((await tabPresenter.getAll()).map((t) => t.pinned)).toEqual([
false,
false,
]);
diff --git a/test/background/operators/impls/UnpinTabOperator.test.ts b/test/background/operators/impls/UnpinTabOperator.test.ts
index 745f48c..c30c94f 100644
--- a/test/background/operators/impls/UnpinTabOperator.test.ts
+++ b/test/background/operators/impls/UnpinTabOperator.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import UnpinTabOperator from "../../../../src/background/operators/impls/UnpinTabOperator";
import MockTabPresenter from "../../mock/MockTabPresenter";
@@ -19,7 +18,7 @@ describe("UnpinTabOperator", () => {
await sut.run();
const pins = (await tabPresenter.getAll()).map((t) => t.pinned);
- expect(pins).to.deep.equal([false, true]);
+ expect(pins).toEqual([false, true]);
});
});
});
diff --git a/test/background/operators/impls/ZoomInOperator.test.ts b/test/background/operators/impls/ZoomInOperator.test.ts
index 097e760..1d42421 100644
--- a/test/background/operators/impls/ZoomInOperator.test.ts
+++ b/test/background/operators/impls/ZoomInOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import ZoomInOperator from "../../../../src/background/operators/impls/ZoomInOperator";
import MockZoomPresenter from "../../mock/MockZoomPresenter";
@@ -6,12 +5,14 @@ describe("ZoomInOperator", () => {
describe("#run", () => {
it("zoom-out the current tab", async () => {
const zoomPresenter = new MockZoomPresenter();
- const mock = sinon.mock(zoomPresenter).expects("zoomIn").once();
+ const zoomInSpy = jest
+ .spyOn(zoomPresenter, "zoomIn")
+ .mockReturnValue(Promise.resolve());
const sut = new ZoomInOperator(zoomPresenter);
await sut.run();
- mock.verify();
+ expect(zoomInSpy).toBeCalled();
});
});
});
diff --git a/test/background/operators/impls/ZoomOperatorFactoryChain.test.ts b/test/background/operators/impls/ZoomOperatorFactoryChain.test.ts
index 10c1cee..ab40a86 100644
--- a/test/background/operators/impls/ZoomOperatorFactoryChain.test.ts
+++ b/test/background/operators/impls/ZoomOperatorFactoryChain.test.ts
@@ -1,5 +1,4 @@
import "reflect-metadata";
-import { expect } from "chai";
import ZoomOperatorFactoryChain from "../../../../src/background/operators/impls/ZoomOperatorFactoryChain";
import MockZoomPresenter from "../../mock/MockZoomPresenter";
import ZoomInOperator from "../../../../src/background/operators/impls/ZoomInOperator";
@@ -13,16 +12,16 @@ describe("ZoomOperatorFactoryChain", () => {
const zoomPresenter = new MockZoomPresenter();
const sut = new ZoomOperatorFactoryChain(zoomPresenter);
- expect(sut.create({ type: operations.ZOOM_IN })).to.be.instanceOf(
+ expect(sut.create({ type: operations.ZOOM_IN })).toBeInstanceOf(
ZoomInOperator
);
- expect(sut.create({ type: operations.ZOOM_OUT })).to.be.instanceOf(
+ expect(sut.create({ type: operations.ZOOM_OUT })).toBeInstanceOf(
ZoomOutOperator
);
- expect(sut.create({ type: operations.ZOOM_NEUTRAL })).to.be.instanceOf(
+ expect(sut.create({ type: operations.ZOOM_NEUTRAL })).toBeInstanceOf(
ResetZoomOperator
);
- expect(sut.create({ type: operations.CANCEL })).to.be.null;
+ expect(sut.create({ type: operations.CANCEL })).toBeNull;
});
});
});
diff --git a/test/background/operators/impls/ZoomOutOperator.test.ts b/test/background/operators/impls/ZoomOutOperator.test.ts
index e0bbcd9..3165707 100644
--- a/test/background/operators/impls/ZoomOutOperator.test.ts
+++ b/test/background/operators/impls/ZoomOutOperator.test.ts
@@ -1,4 +1,3 @@
-import sinon from "sinon";
import ZoomOutOperator from "../../../../src/background/operators/impls/ZoomOutOperator";
import MockZoomPresenter from "../../mock/MockZoomPresenter";
@@ -6,12 +5,14 @@ describe("ZoomOutOperator", () => {
describe("#run", () => {
it("zoom-in the current tab", async () => {
const zoomPresenter = new MockZoomPresenter();
- const mock = sinon.mock(zoomPresenter).expects("zoomOut").once();
+ const zoomOutSpy = jest
+ .spyOn(zoomPresenter, "zoomOut")
+ .mockReturnValue(Promise.resolve());
const sut = new ZoomOutOperator(zoomPresenter);
await sut.run();
- mock.verify();
+ expect(zoomOutSpy).toBeCalled();
});
});
});
diff --git a/test/background/repositories/FindRepository.test.ts b/test/background/repositories/FindRepository.test.ts
index d8c9506..88d5e71 100644
--- a/test/background/repositories/FindRepository.test.ts
+++ b/test/background/repositories/FindRepository.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import { FindRepositoryImpl } from "../../../src/background/repositories/FindRepository";
describe("background/repositories/FindRepositoryImpl", () => {
@@ -10,18 +9,18 @@ describe("background/repositories/FindRepositoryImpl", () => {
describe("global keyword", () => {
it("get and set a keyword", async () => {
- expect(await sut.getGlobalKeyword()).to.be.undefined;
+ expect(await sut.getGlobalKeyword()).toBeUndefined;
await sut.setGlobalKeyword("Hello, world");
const keyword = await sut.getGlobalKeyword();
- expect(keyword).to.equal("Hello, world");
+ expect(keyword).toEqual("Hello, world");
});
});
describe("local state", () => {
it("get and set a keyword", async () => {
- expect(await sut.getLocalState(10)).to.be.undefined;
+ expect(await sut.getLocalState(10)).toBeUndefined;
await sut.setLocalState(10, {
keyword: "Hello, world",
@@ -29,10 +28,10 @@ describe("background/repositories/FindRepositoryImpl", () => {
});
const state = await sut.getLocalState(10);
- expect(state?.keyword).to.equal("Hello, world");
- expect(state?.frameId).to.equal(11);
+ expect(state?.keyword).toEqual("Hello, world");
+ expect(state?.frameId).toEqual(11);
- expect(await sut.getLocalState(20)).to.be.undefined;
+ expect(await sut.getLocalState(20)).toBeUndefined;
});
});
});
diff --git a/test/background/repositories/Mark.test.ts b/test/background/repositories/Mark.test.ts
index 3b054e5..bdee3b7 100644
--- a/test/background/repositories/Mark.test.ts
+++ b/test/background/repositories/Mark.test.ts
@@ -1,5 +1,4 @@
import MarkRepository from "../../../src/background/repositories/MarkRepository";
-import { expect } from "chai";
describe("background/repositories/mark", () => {
let repository: MarkRepository;
@@ -14,12 +13,12 @@ describe("background/repositories/mark", () => {
await repository.setMark("A", mark);
let got = (await repository.getMark("A"))!;
- expect(got.tabId).to.equal(1);
- expect(got.url).to.equal("http://example.com");
- expect(got.x).to.equal(10);
- expect(got.y).to.equal(30);
+ expect(got.tabId).toEqual(1);
+ expect(got.url).toEqual("http://example.com");
+ expect(got.x).toEqual(10);
+ expect(got.y).toEqual(30);
got = (await repository.getMark("B"))!;
- expect(got).to.be.undefined;
+ expect(got).toBeUndefined;
});
});
diff --git a/test/background/repositories/ReadyFrameRepository.test.ts b/test/background/repositories/ReadyFrameRepository.test.ts
index 71f20af..fb4d34a 100644
--- a/test/background/repositories/ReadyFrameRepository.test.ts
+++ b/test/background/repositories/ReadyFrameRepository.test.ts
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import { ReadyFrameRepositoryImpl } from "../../../src/background/repositories/ReadyFrameRepository";
describe("background/repositories/ReadyFrameRepositoryImpl", () => {
@@ -9,7 +8,7 @@ describe("background/repositories/ReadyFrameRepositoryImpl", () => {
});
it("get and set a keyword", async () => {
- expect(await sut.getFrameIds(1)).to.be.undefined;
+ expect(await sut.getFrameIds(1)).toBeUndefined;
await sut.addFrameId(1, 10);
await sut.addFrameId(1, 12);
@@ -18,16 +17,16 @@ describe("background/repositories/ReadyFrameRepositoryImpl", () => {
await sut.addFrameId(2, 21);
await sut.addFrameId(2, 21);
- expect(await sut.getFrameIds(1)).to.deep.equal([10, 11, 12]);
- expect(await sut.getFrameIds(2)).to.deep.equal([20, 21]);
+ expect(await sut.getFrameIds(1)).toEqual([10, 11, 12]);
+ expect(await sut.getFrameIds(2)).toEqual([20, 21]);
await sut.removeFrameId(2, 21);
- expect(await sut.getFrameIds(2)).to.deep.equal([20, 21]);
+ expect(await sut.getFrameIds(2)).toEqual([20, 21]);
await sut.removeFrameId(2, 21);
- expect(await sut.getFrameIds(2)).to.deep.equal([20]);
+ expect(await sut.getFrameIds(2)).toEqual([20]);
await sut.removeFrameId(2, 20);
- expect(await sut.getFrameIds(2)).to.be.undefined;
+ expect(await sut.getFrameIds(2)).toBeUndefined;
});
});
diff --git a/test/background/usecases/SettingUseCase.test.ts b/test/background/usecases/SettingUseCase.test.ts
index 8a4c2b2..395e8a4 100644
--- a/test/background/usecases/SettingUseCase.test.ts
+++ b/test/background/usecases/SettingUseCase.test.ts
@@ -7,9 +7,7 @@ import Settings, {
DefaultSetting,
} from "../../../src/shared/settings/Settings";
import Notifier from "../../../src/background/presenters/Notifier";
-import { expect } from "chai";
import Properties from "../../../src/shared/settings/Properties";
-import sinon from "sinon";
class MockSettingRepository implements SettingRepository {
load(): Promise<SettingData | null> {
@@ -77,17 +75,15 @@ describe("SettingUseCase", () => {
hintchars: "abcd1234",
}),
});
- sinon
- .stub(cachedSettingRepository, "get")
- .returns(Promise.resolve(settings));
+ jest.spyOn(cachedSettingRepository, "get").mockResolvedValue(settings);
const got = await sut.getCached();
- expect(got.properties.hintchars).to.equal("abcd1234");
+ expect(got.properties.hintchars).toEqual("abcd1234");
});
});
describe("reload", () => {
- context("when sync is not set", () => {
+ describe("when sync is not set", () => {
it("loads settings from local storage", async () => {
const settings = new Settings({
keymaps: DefaultSetting.keymaps,
@@ -102,21 +98,19 @@ describe("SettingUseCase", () => {
json: JSONTextSettings.fromSettings(settings).toJSONText(),
});
- sinon
- .stub(syncSettingRepository, "load")
- .returns(Promise.resolve(null));
- sinon
- .stub(localSettingRepository, "load")
- .returns(Promise.resolve(settingData));
+ jest.spyOn(syncSettingRepository, "load").mockResolvedValue(null);
+ jest
+ .spyOn(localSettingRepository, "load")
+ .mockResolvedValue(settingData);
await sut.reload();
const current = await cachedSettingRepository.get();
- expect(current.properties.hintchars).to.equal("abcd1234");
+ expect(current.properties.hintchars).toEqual("abcd1234");
});
});
- context("when local is not set", () => {
+ describe("when local is not set", () => {
it("loads settings from sync storage", async () => {
const settings = new Settings({
keymaps: DefaultSetting.keymaps,
@@ -131,37 +125,29 @@ describe("SettingUseCase", () => {
json: JSONTextSettings.fromSettings(settings).toJSONText(),
});
- sinon
- .stub(syncSettingRepository, "load")
- .returns(Promise.resolve(settingData));
- sinon
- .stub(localSettingRepository, "load")
- .returns(Promise.resolve(null));
+ jest
+ .spyOn(syncSettingRepository, "load")
+ .mockResolvedValue(settingData);
+ jest.spyOn(localSettingRepository, "load").mockResolvedValue(null);
await sut.reload();
const current = await cachedSettingRepository.get();
- expect(current.properties.hintchars).to.equal("aaaa1111");
+ expect(current.properties.hintchars).toEqual("aaaa1111");
});
});
- context("neither local nor sync not set", () => {
- it("loads default settings", async () => {
- it("loads settings from sync storage", async () => {
- sinon
- .stub(syncSettingRepository, "load")
- .returns(Promise.resolve(null));
- sinon
- .stub(localSettingRepository, "load")
- .returns(Promise.resolve(null));
-
- await sut.reload();
-
- const current = await cachedSettingRepository.get();
- expect(current.properties.hintchars).to.equal(
- DefaultSetting.properties.hintchars
- );
- });
+ describe("neither local nor sync not set", () => {
+ it("loads settings from sync storage", async () => {
+ jest.spyOn(syncSettingRepository, "load").mockResolvedValue(null);
+ jest.spyOn(localSettingRepository, "load").mockResolvedValue(null);
+
+ await sut.reload();
+
+ const current = await cachedSettingRepository.get();
+ expect(current.properties.hintchars).toEqual(
+ DefaultSetting.properties.hintchars
+ );
});
});
});
diff --git a/test/background/usecases/StartFindUseCase.test.ts b/test/background/usecases/StartFindUseCase.test.ts
index 24e1fdc..0bfe18a 100644
--- a/test/background/usecases/StartFindUseCase.test.ts
+++ b/test/background/usecases/StartFindUseCase.test.ts
@@ -1,4 +1,3 @@
-import * as sinon from "sinon";
import MockFindClient from "../mock/MockFindClient";
import MockFindRepository from "../mock/MockFindRepository";
import MockConsoleClient from "../mock/MockConsoleClient";
@@ -21,160 +20,144 @@ describe("StartFindUseCase", () => {
frameRepository
);
- beforeEach(async () => {
- sinon.restore();
+ const getFrameIdsSpy = jest
+ .spyOn(frameRepository, "getFrameIds")
+ .mockResolvedValue(frameIds);
+ const clearSelectionSpy = jest
+ .spyOn(findClient, "clearSelection")
+ .mockReturnValue(Promise.resolve());
+ const findNextSpy = jest.spyOn(findClient, "findNext");
+ const setLocalStateSpy = jest
+ .spyOn(findRepository, "setLocalState")
+ .mockReturnValue(Promise.resolve());
- sinon
- .stub(frameRepository, "getFrameIds")
- .returns(Promise.resolve(frameIds));
+ beforeEach(async () => {
+ getFrameIdsSpy.mockClear();
+ clearSelectionSpy.mockClear();
+ findNextSpy.mockClear();
+ setLocalStateSpy.mockClear();
});
describe("startFind", () => {
it("starts a find with a keyword", async () => {
- const mockFindClient = sinon.mock(findClient);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 0);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 100);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 101);
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 0, keyword)
- .returns(Promise.resolve(false));
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 100, keyword)
- .returns(Promise.resolve(true));
- const mockFindRepository = sinon.mock(findRepository);
- mockFindRepository
- .expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameId: 100 });
- const mockConsoleClient = sinon.mock(consoleClient);
- mockConsoleClient
- .expects("showInfo")
- .withArgs(currentTabId, "Pattern found: " + keyword);
+ findNextSpy.mockResolvedValueOnce(false).mockResolvedValueOnce(true);
+ const showInfoSpy = jest
+ .spyOn(consoleClient, "showInfo")
+ .mockReturnValue(Promise.resolve());
await sut.startFind(currentTabId, keyword);
- mockFindClient.verify();
- mockFindRepository.verify();
- mockConsoleClient.verify();
+ expect(clearSelectionSpy).toBeCalledTimes(3);
+ expect(clearSelectionSpy.mock.calls[0][1]).toEqual(0);
+ expect(clearSelectionSpy.mock.calls[1][1]).toEqual(100);
+ expect(clearSelectionSpy.mock.calls[2][1]).toEqual(101);
+ expect(findNextSpy).toBeCalledTimes(2);
+ expect(findNextSpy.mock.calls[0][1]).toEqual(0);
+ expect(findNextSpy.mock.calls[1][1]).toEqual(100);
+ expect(setLocalStateSpy).toBeCalledWith(currentTabId, {
+ keyword,
+ frameId: 100,
+ });
+ expect(showInfoSpy).toBeCalledWith(
+ currentTabId,
+ "Pattern found: " + keyword
+ );
});
it("starts a find with last local state", async () => {
- const mockFindClient = sinon.mock(findClient);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 0);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 100);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 101);
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 0, keyword)
- .returns(Promise.resolve(false));
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 100, keyword)
- .returns(Promise.resolve(true));
- const mockFindRepository = sinon.mock(findRepository);
- mockFindRepository
- .expects("getLocalState")
- .withArgs(currentTabId)
- .returns(Promise.resolve({ keyword, frameId: 0 }));
- mockFindRepository
- .expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameId: 100 });
- const mockConsoleClient = sinon.mock(consoleClient);
- mockConsoleClient
- .expects("showInfo")
- .withArgs(currentTabId, "Pattern found: " + keyword);
+ findNextSpy.mockResolvedValueOnce(false).mockResolvedValueOnce(true);
+ const getLocalStateSpy = jest
+ .spyOn(findRepository, "getLocalState")
+ .mockResolvedValue({ keyword, frameId: 0 });
+ const showInfoSpy = jest
+ .spyOn(consoleClient, "showInfo")
+ .mockReturnValue(Promise.resolve());
await sut.startFind(currentTabId, undefined);
- mockFindClient.verify();
- mockFindRepository.verify();
- mockConsoleClient.verify();
+ expect(clearSelectionSpy).toBeCalledTimes(3);
+ expect(clearSelectionSpy.mock.calls[0][1]).toEqual(0);
+ expect(clearSelectionSpy.mock.calls[1][1]).toEqual(100);
+ expect(clearSelectionSpy.mock.calls[2][1]).toEqual(101);
+ expect(findNextSpy).toBeCalledTimes(2);
+ expect(findNextSpy.mock.calls[0][1]).toEqual(0);
+ expect(findNextSpy.mock.calls[1][1]).toEqual(100);
+ expect(getLocalStateSpy).toBeCalledWith(currentTabId);
+ expect(setLocalStateSpy).toBeCalledWith(currentTabId, {
+ keyword,
+ frameId: 100,
+ });
+ expect(showInfoSpy).toBeCalledWith(
+ currentTabId,
+ "Pattern found: " + keyword
+ );
});
it("starts a find with last global state", async () => {
- const mockFindClient = sinon.mock(findClient);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 0);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 100);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 101);
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 0, keyword)
- .returns(Promise.resolve(false));
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 100, keyword)
- .returns(Promise.resolve(true));
- const mockFindRepository = sinon.mock(findRepository);
- mockFindRepository
- .expects("getLocalState")
- .withArgs(currentTabId)
- .returns(Promise.resolve(undefined));
- mockFindRepository
- .expects("getGlobalKeyword")
- .returns(Promise.resolve(keyword));
- mockFindRepository
- .expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameId: 100 });
- const mockConsoleClient = sinon.mock(consoleClient);
- mockConsoleClient
- .expects("showInfo")
- .withArgs(currentTabId, "Pattern found: " + keyword);
+ findNextSpy.mockResolvedValueOnce(false).mockResolvedValueOnce(true);
+ const getLocalStateSpy = jest
+ .spyOn(findRepository, "getLocalState")
+ .mockResolvedValue(undefined);
+ jest.spyOn(findRepository, "getGlobalKeyword").mockResolvedValue(keyword);
+ const showInfoSpy = jest
+ .spyOn(consoleClient, "showInfo")
+ .mockReturnValue(Promise.resolve());
await sut.startFind(currentTabId, undefined);
- mockFindClient.verify();
- mockFindRepository.verify();
- mockConsoleClient.verify();
+ expect(clearSelectionSpy).toBeCalledTimes(3);
+ expect(clearSelectionSpy.mock.calls[0][1]).toEqual(0);
+ expect(clearSelectionSpy.mock.calls[1][1]).toEqual(100);
+ expect(clearSelectionSpy.mock.calls[2][1]).toEqual(101);
+ expect(findNextSpy).toBeCalledTimes(2);
+ expect(findNextSpy.mock.calls[0][1]).toEqual(0);
+ expect(findNextSpy.mock.calls[1][1]).toEqual(100);
+ expect(getLocalStateSpy).toBeCalledWith(currentTabId);
+ expect(setLocalStateSpy).toBeCalledWith(currentTabId, {
+ keyword,
+ frameId: 100,
+ });
+ expect(showInfoSpy).toBeCalledWith(
+ currentTabId,
+ "Pattern found: " + keyword
+ );
});
it("shows an error when pattern not found", async () => {
- const mockFindClient = sinon.mock(findClient);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 0);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 100);
- mockFindClient.expects("clearSelection").withArgs(currentTabId, 101);
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 0, keyword)
- .returns(Promise.resolve(false));
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 100, keyword)
- .returns(Promise.resolve(false));
- mockFindClient
- .expects("findNext")
- .withArgs(currentTabId, 101, keyword)
- .returns(Promise.resolve(false));
- const mockFindRepository = sinon.mock(findRepository);
- mockFindRepository.expects("setLocalState").never();
- const mockConsoleClient = sinon.mock(consoleClient);
- mockConsoleClient
- .expects("showError")
- .withArgs(currentTabId, "Pattern not found: " + keyword);
+ findNextSpy.mockResolvedValue(false);
+ const showErrorSpy = jest
+ .spyOn(consoleClient, "showError")
+ .mockReturnValue(Promise.resolve());
await sut.startFind(currentTabId, keyword);
- mockFindClient.verify();
- mockFindRepository.verify();
- mockConsoleClient.verify();
+ expect(clearSelectionSpy).toBeCalledTimes(3);
+ expect(clearSelectionSpy.mock.calls[0][1]).toEqual(0);
+ expect(clearSelectionSpy.mock.calls[1][1]).toEqual(100);
+ expect(clearSelectionSpy.mock.calls[2][1]).toEqual(101);
+ expect(setLocalStateSpy).not.toBeCalled();
+ expect(showErrorSpy).toBeCalledWith(
+ currentTabId,
+ "Pattern not found: " + keyword
+ );
});
it("shows an error when no last keywords", async () => {
- sinon
- .stub(findRepository, "getLocalState")
- .returns(Promise.resolve(undefined));
- sinon
- .stub(findRepository, "getGlobalKeyword")
- .returns(Promise.resolve(undefined));
-
- const mockConsoleClient = sinon.mock(consoleClient);
- mockConsoleClient
- .expects("showError")
- .withArgs(currentTabId, "No previous search keywords");
+ jest.spyOn(findRepository, "getLocalState").mockResolvedValue(undefined);
+ jest
+ .spyOn(findRepository, "getGlobalKeyword")
+ .mockResolvedValue(undefined);
+
+ const showErrorSpy = jest
+ .spyOn(consoleClient, "showError")
+ .mockReturnValue(Promise.resolve());
await sut.startFind(currentTabId, undefined);
- mockConsoleClient.verify();
+ expect(showErrorSpy).toBeCalledWith(
+ currentTabId,
+ "No previous search keywords"
+ );
});
});
});
diff --git a/test/background/usecases/parsers.test.ts b/test/background/usecases/parsers.test.ts
index 019b56e..db26b7a 100644
--- a/test/background/usecases/parsers.test.ts
+++ b/test/background/usecases/parsers.test.ts
@@ -1,42 +1,36 @@
import * as parsers from "../../../src/background/usecases/parsers";
-import { expect } from "chai";
describe("shared/commands/parsers", () => {
describe("#parsers.parseSetOption", () => {
it("parse set string", () => {
const [key, value] = parsers.parseSetOption("hintchars=abcdefgh");
- expect(key).to.equal("hintchars");
- expect(value).to.equal("abcdefgh");
+ expect(key).toEqual("hintchars");
+ expect(value).toEqual("abcdefgh");
});
it("parse set empty string", () => {
const [key, value] = parsers.parseSetOption("hintchars=");
- expect(key).to.equal("hintchars");
- expect(value).to.equal("");
+ expect(key).toEqual("hintchars");
+ expect(value).toEqual("");
});
it("parse set boolean", () => {
let [key, value] = parsers.parseSetOption("smoothscroll");
- expect(key).to.equal("smoothscroll");
- expect(value).to.be.true;
+ expect(key).toEqual("smoothscroll");
+ expect(value).toBeTruthy;
[key, value] = parsers.parseSetOption("nosmoothscroll");
- expect(key).to.equal("smoothscroll");
- expect(value).to.be.false;
+ expect(key).toEqual("smoothscroll");
+ expect(value).toBeFalsy;
});
it("throws error on unknown property", () => {
- expect(() => parsers.parseSetOption("encoding=utf-8")).to.throw(
- Error,
+ expect(() => parsers.parseSetOption("encoding=utf-8")).toThrowError(
"Unknown"
);
- expect(() => parsers.parseSetOption("paste")).to.throw(Error, "Unknown");
- expect(() => parsers.parseSetOption("nopaste")).to.throw(
- Error,
- "Unknown"
- );
- expect(() => parsers.parseSetOption("smoothscroll=yes")).to.throw(
- Error,
+ expect(() => parsers.parseSetOption("paste")).toThrowError("Unknown");
+ expect(() => parsers.parseSetOption("nopaste")).toThrowError("Unknown");
+ expect(() => parsers.parseSetOption("smoothscroll=yes")).toThrowError(
"Invalid argument"
);
});