diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2021-10-10 01:42:37 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-10 01:42:37 +0000 |
commit | dfcefe1b84cc96ead1c8d8f9aa65ff05ccd70378 (patch) | |
tree | 12f1a4ed6da8fd96c034d23bcf08b1535bca1113 /test | |
parent | 24f4f06db6572d81cadfe191f36c433a79985871 (diff) | |
parent | 039095e18562c44edda2c5a83a3d82c2e220b370 (diff) |
Merge pull request #1267 from ueokande/move-to-jest
Move to Jest
Diffstat (limited to 'test')
123 files changed, 1194 insertions, 1452 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" ); }); diff --git a/test/console/app/actions.test.ts b/test/console/app/actions.test.ts index 2f9dc71..c903428 100644 --- a/test/console/app/actions.test.ts +++ b/test/console/app/actions.test.ts @@ -7,56 +7,49 @@ import { SHOW_FIND, SHOW_INFO, } from "../../../src/console/app/actions"; -import { expect } from "chai"; - -import browserFake from "webextensions-api-fake"; describe("console actions", () => { - beforeEach(() => { - (global as any).browser = browserFake(); - }); - describe("hide", () => { it("create CONSOLE_HIDE action", () => { const action = consoleActions.hide(); - expect(action.type).to.equal(HIDE); + expect(action.type).toEqual(HIDE); }); }); describe("showCommand", () => { it("create CONSOLE_SHOW_COMMAND action", async () => { const action = await consoleActions.showCommand("hello"); - expect(action.type).to.equal(SHOW_COMMAND); - expect(action.text).to.equal("hello"); + expect(action.type).toEqual(SHOW_COMMAND); + expect(action.text).toEqual("hello"); }); }); describe("showFind", () => { it("create CONSOLE_SHOW_FIND action", () => { const action = consoleActions.showFind(); - expect(action.type).to.equal(SHOW_FIND); + expect(action.type).toEqual(SHOW_FIND); }); }); describe("showError", () => { it("create CONSOLE_SHOW_ERROR action", () => { const action = consoleActions.showError("an error"); - expect(action.type).to.equal(SHOW_ERROR); - expect(action.text).to.equal("an error"); + expect(action.type).toEqual(SHOW_ERROR); + expect(action.text).toEqual("an error"); }); }); describe("showInfo", () => { it("create CONSOLE_SHOW_INFO action", () => { const action = consoleActions.showInfo("an info"); - expect(action.type).to.equal(SHOW_INFO); - expect(action.text).to.equal("an info"); + expect(action.type).toEqual(SHOW_INFO); + expect(action.text).toEqual("an info"); }); }); describe("hideCommand", () => { it("create CONSOLE_HIDE_COMMAND action", () => { const action = consoleActions.hideCommand(); - expect(action.type).to.equal(HIDE_COMMAND); + expect(action.type).toEqual(HIDE_COMMAND); }); }); }); diff --git a/test/console/app/reducer.test.ts b/test/console/app/reducer.test.ts index 4406adc..eac2012 100644 --- a/test/console/app/reducer.test.ts +++ b/test/console/app/reducer.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import reducer, { defaultState, State } from "../../../src/console/app/recuer"; import { hide, @@ -18,7 +17,7 @@ describe("app reducer", () => { }; const nextState = reducer(initialState, hide()); - expect(nextState.mode).to.be.empty; + expect(nextState.mode).toHaveLength(0); }); }); @@ -26,8 +25,8 @@ describe("app reducer", () => { it("switches to command mode with a message", () => { const nextState = reducer(defaultState, showCommand("open ")); - expect(nextState.mode).equals("command"); - expect(nextState.consoleText).equals("open "); + expect(nextState.mode).toEqual("command"); + expect(nextState.consoleText).toEqual("open "); }); }); @@ -35,7 +34,7 @@ describe("app reducer", () => { it("switches to find mode with a message", () => { const nextState = reducer(defaultState, showFind()); - expect(nextState.mode).equals("find"); + expect(nextState.mode).toEqual("find"); }); }); @@ -43,8 +42,8 @@ describe("app reducer", () => { it("switches to error message mode with a message", () => { const nextState = reducer(defaultState, showError("error occurs")); - expect(nextState.mode).equals("error"); - expect(nextState.messageText).equals("error occurs"); + expect(nextState.mode).toEqual("error"); + expect(nextState.messageText).toEqual("error occurs"); }); }); @@ -52,8 +51,8 @@ describe("app reducer", () => { it("switches to info message mode with a message", () => { const nextState = reducer(defaultState, showInfo("what's up")); - expect(nextState.mode).equals("info"); - expect(nextState.messageText).equals("what's up"); + expect(nextState.mode).toEqual("info"); + expect(nextState.messageText).toEqual("what's up"); }); }); @@ -66,7 +65,7 @@ describe("app reducer", () => { }; const nextState = reducer(initialState, hideCommand()); - expect(nextState.mode).to.be.empty; + expect(nextState.mode).toHaveLength(0); }); }); @@ -78,7 +77,7 @@ describe("app reducer", () => { }; const nextState = reducer(initialState, hideCommand()); - expect(nextState.mode).equals("info"); + expect(nextState.mode).toEqual("info"); }); }); }); diff --git a/test/console/commandline/CommandLineParser.test.ts b/test/console/commandline/CommandLineParser.test.ts index 7cba04c..d187e1e 100644 --- a/test/console/commandline/CommandLineParser.test.ts +++ b/test/console/commandline/CommandLineParser.test.ts @@ -2,27 +2,26 @@ import CommandLineParser, { InputPhase, } from "../../../src/console/commandline/CommandLineParser"; import { Command } from "../../../src/shared/Command"; -import { expect } from "chai"; describe("CommandLineParser", () => { describe("#inputPhase", () => { it("returns parsed command-line", () => { const sut = new CommandLineParser(); - expect(sut.inputPhase("")).to.equal(InputPhase.OnCommand); - expect(sut.inputPhase("op")).to.equal(InputPhase.OnCommand); - expect(sut.inputPhase("open ")).to.equal(InputPhase.OnArgs); - expect(sut.inputPhase("open apple")).to.equal(InputPhase.OnArgs); + expect(sut.inputPhase("")).toEqual(InputPhase.OnCommand); + expect(sut.inputPhase("op")).toEqual(InputPhase.OnCommand); + expect(sut.inputPhase("open ")).toEqual(InputPhase.OnArgs); + expect(sut.inputPhase("open apple")).toEqual(InputPhase.OnArgs); }); }); describe("#parse", () => { it("returns parsed command-line", () => { const sut = new CommandLineParser(); - expect(sut.parse("open google apple")).to.deep.equal({ + expect(sut.parse("open google apple")).toEqual({ command: Command.Open, args: "google apple", }); - expect(sut.parse("qa")).to.deep.equal({ + expect(sut.parse("qa")).toEqual({ command: Command.QuitAll, args: "", }); diff --git a/test/console/commandline/CommandParser.test.ts b/test/console/commandline/CommandParser.test.ts index f72afd6..a8e82df 100644 --- a/test/console/commandline/CommandParser.test.ts +++ b/test/console/commandline/CommandParser.test.ts @@ -2,16 +2,15 @@ import CommandParser, { UnknownCommandError, } from "../../../src/console/commandline/CommandParser"; import { Command } from "../../../src/shared/Command"; -import { expect } from "chai"; describe("CommandParser", () => { describe("#parse", () => { it("returns matched command with the string", () => { const sut = new CommandParser(); - expect(sut.parse("open")).to.equal(Command.Open); - expect(sut.parse("w")).to.equal(Command.WindowOpen); - expect(sut.parse("bdelete!")).to.equal(Command.BufferDeleteForce); - expect(() => sut.parse("harakiri")).to.throw(UnknownCommandError); + expect(sut.parse("open")).toEqual(Command.Open); + expect(sut.parse("w")).toEqual(Command.WindowOpen); + expect(sut.parse("bdelete!")).toEqual(Command.BufferDeleteForce); + expect(() => sut.parse("harakiri")).toThrow(UnknownCommandError); }); }); }); diff --git a/test/console/completion/reducer.test.ts b/test/console/completion/reducer.test.ts index b742872..43b9807 100644 --- a/test/console/completion/reducer.test.ts +++ b/test/console/completion/reducer.test.ts @@ -2,7 +2,6 @@ import reducer, { defaultState, State, } from "../../../src/console/completion/reducer"; -import { expect } from "chai"; import { initCompletion, selectNext, @@ -20,7 +19,7 @@ describe("completion reducer", () => { initCompletion([CompletionType.Bookmarks, CompletionType.History]) ); - expect(nextState.completionTypes).deep.equals([ + expect(nextState.completionTypes).toEqual([ CompletionType.Bookmarks, CompletionType.History, ]); @@ -31,7 +30,7 @@ describe("completion reducer", () => { it("sets a completion source", () => { const nextState = reducer(defaultState, setCompletionSource("open ")); - expect(nextState.completionSource).equals("open "); + expect(nextState.completionSource).toEqual("open "); }); }); @@ -51,7 +50,7 @@ describe("completion reducer", () => { ]) ); - expect(nextState.completions).deep.equals([ + expect(nextState.completions).toEqual([ { name: "Apple", items: [{}, {}], @@ -65,25 +64,25 @@ describe("completion reducer", () => { }); describe("selectNext", () => { - context("when no completion groups", () => { + describe("when no completion groups", () => { it("does nothing", () => { const nextState = reducer(defaultState, selectNext()); - expect(nextState.select).equals(-1); + expect(nextState.select).toEqual(-1); }); }); - context("when no completion items", () => { + describe("when no completion items", () => { it("does nothing", () => { const state = { ...defaultState, completions: [{ name: "apple", items: [] }], }; const nextState = reducer(state, selectNext()); - expect(nextState.select).equals(-1); + expect(nextState.select).toEqual(-1); }); }); - context("when completions exist", () => { + describe("when completions exist", () => { it("selects next selection", () => { let state: State = { ...defaultState, @@ -101,40 +100,40 @@ describe("completion reducer", () => { }; state = reducer(state, selectNext()); - expect(state.select).equals(0); + expect(state.select).toEqual(0); state = reducer(state, selectNext()); - expect(state.select).equals(1); + expect(state.select).toEqual(1); state = reducer(state, selectNext()); - expect(state.select).equals(2); + expect(state.select).toEqual(2); state = reducer(state, selectNext()); - expect(state.select).equals(-1); + expect(state.select).toEqual(-1); }); }); }); describe("selectPrev", () => { - context("when no completion groups", () => { + describe("when no completion groups", () => { it("does nothing", () => { const nextState = reducer(defaultState, selectPrev()); - expect(nextState.select).equals(-1); + expect(nextState.select).toEqual(-1); }); - context("when no completion items", () => { + describe("when no completion items", () => { it("does nothing", () => { const state = { ...defaultState, completions: [{ name: "apple", items: [] }], }; const nextState = reducer(state, selectPrev()); - expect(nextState.select).equals(-1); + expect(nextState.select).toEqual(-1); }); }); }); - context("when completions exist", () => { + describe("when completions exist", () => { it("selects a previous completion", () => { let state: State = { ...defaultState, @@ -152,16 +151,16 @@ describe("completion reducer", () => { }; state = reducer(state, selectPrev()); - expect(state).to.have.property("select", 2); + expect(state).toHaveProperty("select", 2); state = reducer(state, selectPrev()); - expect(state).to.have.property("select", 1); + expect(state).toHaveProperty("select", 1); state = reducer(state, selectPrev()); - expect(state).to.have.property("select", 0); + expect(state).toHaveProperty("select", 0); state = reducer(state, selectPrev()); - expect(state).to.have.property("select", -1); + expect(state).toHaveProperty("select", -1); }); }); }); diff --git a/test/console/components/ErrorMessage.test.tsx b/test/console/components/ErrorMessage.test.tsx index 46ec0b0..45b3052 100644 --- a/test/console/components/ErrorMessage.test.tsx +++ b/test/console/components/ErrorMessage.test.tsx @@ -1,17 +1,16 @@ import React from "react"; import ReactTestRenderer from "react-test-renderer"; -import { expect } from "chai"; import ErrorMessage from "../../../src/console/components/ErrorMessage"; describe("console/components/console/completion/ErrorMessage", () => { it("renders an error message", () => { const root = ReactTestRenderer.create( - <ErrorMessage mode="error">Hello!</ErrorMessage> + <ErrorMessage>Hello!</ErrorMessage> ).root; const p = root.findByType("p"); - expect(p.props["role"]).to.equal("alert"); - expect(p.children).to.deep.equal(["Hello!"]); + expect(p.props["role"]).toEqual("alert"); + expect(p.children).toEqual(["Hello!"]); }); }); diff --git a/test/console/components/InfoMessage.test.tsx b/test/console/components/InfoMessage.test.tsx index 5b678ff..9f3a68d 100644 --- a/test/console/components/InfoMessage.test.tsx +++ b/test/console/components/InfoMessage.test.tsx @@ -1,17 +1,16 @@ import React from "react"; import ReactTestRenderer from "react-test-renderer"; -import { expect } from "chai"; import InfoMessage from "../../../src/console/components/InfoMessage"; describe("console/components/console/completion/InfoMessage", () => { it("renders an information message", () => { const root = ReactTestRenderer.create( - <InfoMessage mode="info">Hello!</InfoMessage> + <InfoMessage>Hello!</InfoMessage> ).root; const p = root.findByType("p"); - expect(p.props["role"]).to.equal("status"); - expect(p.children).to.deep.equal(["Hello!"]); + expect(p.props["role"]).toEqual("status"); + expect(p.children).toEqual(["Hello!"]); }); }); diff --git a/test/console/components/console/Completion.test.tsx b/test/console/components/console/Completion.test.tsx index 9b47637..7dd634f 100644 --- a/test/console/components/console/Completion.test.tsx +++ b/test/console/components/console/Completion.test.tsx @@ -1,7 +1,6 @@ import React from "react"; import Completion from "../../../../src/console/components/console/Completion"; import ReactTestRenderer from "react-test-renderer"; -import { expect } from "chai"; import CompletionTitle from "../../../../src/console/components/console/CompletionTitle"; import CompletionItem from "../../../../src/console/components/console/CompletionItem"; @@ -31,16 +30,16 @@ describe("console/components/console/completion/Completion", () => { ).root; const groups = root.findAllByProps({ role: "group" }); - expect(groups).to.have.lengthOf(2); + expect(groups).toHaveLength(2); groups.forEach((group, i) => { const title = group.findByType(CompletionTitle); - expect(title.props.title).to.equal(completions[i].name); + expect(title.props.title).toEqual(completions[i].name); const items = group.findAllByType(CompletionItem); - expect(items).to.have.lengthOf(completions[i].items.length); + expect(items).toHaveLength(completions[i].items.length); items.forEach((item, j) => { - expect(item.props.caption).to.equal(completions[i].items[j].caption); + expect(item.props.caption).toEqual(completions[i].items[j].caption); }); }); }); @@ -51,7 +50,7 @@ describe("console/components/console/completion/Completion", () => { ).root; const items = root.findAllByType(CompletionItem); - expect(items[3].props.highlight).to.be.true; + expect(items[3].props.highlight).toBeTruthy; }); it("does not highlight any items", () => { @@ -60,7 +59,7 @@ describe("console/components/console/completion/Completion", () => { ).root; const items = root.findAllByType(CompletionItem); - expect(items.every((item) => item.props.highlight === false)).to.be.true; + expect(items.every((item) => item.props.highlight === false)).toBeTruthy; }); it("limits completion items", () => { @@ -78,7 +77,7 @@ describe("console/components/console/completion/Completion", () => { ) .flat(); - expect(showns).to.deep.equal([ + expect(showns).toEqual([ true, true, true, @@ -96,11 +95,11 @@ describe("console/components/console/completion/Completion", () => { const items = root .findAllByType(CompletionItem) .map((item) => item.props.shown); - expect(items[1]).to.be.true; + expect(items[1]).toBeTruthy; }); it("scrolls up to down with select", () => { - let component: ReturnType<ReactTestRenderer["create"]> | null = null; + let component: ReactTestRenderer.ReactTestRenderer | null = null; ReactTestRenderer.act(() => { component = ReactTestRenderer.create( @@ -108,7 +107,7 @@ describe("console/components/console/completion/Completion", () => { ); }); - const root = component.root; + const root = component!.root; let items = root.findAllByType(CompletionItem); let showns = root @@ -120,7 +119,7 @@ describe("console/components/console/completion/Completion", () => { ].flat() ) .flat(); - expect(showns).to.deep.equal([ + expect(showns).toEqual([ true, true, true, @@ -132,7 +131,7 @@ describe("console/components/console/completion/Completion", () => { ]); ReactTestRenderer.act(() => { - component.update( + component!.update( <Completion completions={completions} size={3} select={2} /> ); }); @@ -146,7 +145,7 @@ describe("console/components/console/completion/Completion", () => { ].flat() ) .flat(); - expect(showns).to.deep.equal([ + expect(showns).toEqual([ false, true, true, @@ -156,10 +155,10 @@ describe("console/components/console/completion/Completion", () => { false, false, ]); - expect(items[2].props.highlight).to.be.true; + expect(items[2].props.highlight).toBeTruthy; ReactTestRenderer.act(() => { - component.update( + component!.update( <Completion completions={completions} size={3} select={3} /> ); }); @@ -173,7 +172,7 @@ describe("console/components/console/completion/Completion", () => { ].flat() ) .flat(); - expect(showns).to.deep.equal([ + expect(showns).toEqual([ false, false, false, @@ -183,18 +182,18 @@ describe("console/components/console/completion/Completion", () => { false, false, ]); - expect(items[3].props.highlight).to.be.true; + expect(items[3].props.highlight).toBeTruthy; }); it("scrolls down to up with select", () => { - let component: ReturnType<ReactTestRenderer["create"]> | null = null; + let component: ReactTestRenderer.ReactTestRenderer | null = null; ReactTestRenderer.act(() => { component = ReactTestRenderer.create( <Completion completions={completions} size={3} select={5} /> ); }); - const root = component.root; + const root = component!.root; let items = root.findAllByType(CompletionItem); let showns = root @@ -207,7 +206,7 @@ describe("console/components/console/completion/Completion", () => { ) .flat(); - expect(showns).to.deep.equal([ + expect(showns).toEqual([ false, false, false, @@ -217,10 +216,10 @@ describe("console/components/console/completion/Completion", () => { true, true, ]); - expect(items[5].props.highlight).to.be.true; + expect(items[5].props.highlight).toBeTruthy; ReactTestRenderer.act(() => { - component.update( + component!.update( <Completion completions={completions} size={3} select={4} /> ); }); @@ -234,7 +233,7 @@ describe("console/components/console/completion/Completion", () => { ].flat() ) .flat(); - expect(showns).to.deep.equal([ + expect(showns).toEqual([ false, false, false, @@ -244,10 +243,10 @@ describe("console/components/console/completion/Completion", () => { true, true, ]); - expect(items[4].props.highlight).to.be.true; + expect(items[4].props.highlight).toBeTruthy; ReactTestRenderer.act(() => { - component.update( + component!.update( <Completion completions={completions} size={3} select={3} /> ); }); @@ -261,7 +260,7 @@ describe("console/components/console/completion/Completion", () => { ].flat() ) .flat(); - expect(showns).to.deep.equal([ + expect(showns).toEqual([ false, false, false, @@ -271,10 +270,10 @@ describe("console/components/console/completion/Completion", () => { true, true, ]); - expect(items[3].props.highlight).to.be.true; + expect(items[3].props.highlight).toBeTruthy; ReactTestRenderer.act(() => { - component.update( + component!.update( <Completion completions={completions} size={3} select={2} /> ); }); @@ -288,7 +287,7 @@ describe("console/components/console/completion/Completion", () => { ].flat() ) .flat(); - expect(showns).to.deep.equal([ + expect(showns).toEqual([ false, false, false, @@ -298,6 +297,6 @@ describe("console/components/console/completion/Completion", () => { false, false, ]); - expect(items[2].props.highlight).to.be.true; + expect(items[2].props.highlight).toBeTruthy; }); }); diff --git a/test/console/components/console/CompletionItem.test.tsx b/test/console/components/console/CompletionItem.test.tsx index 3a4b1f2..ae73b21 100644 --- a/test/console/components/console/CompletionItem.test.tsx +++ b/test/console/components/console/CompletionItem.test.tsx @@ -1,6 +1,5 @@ import React from "react"; import ReactTestRenderer from "react-test-renderer"; -import { expect } from "chai"; import CompletionItem from "../../../../src/console/components/console/CompletionItem"; describe("console/components/console/completion/CompletionItem", () => { @@ -14,8 +13,8 @@ describe("console/components/console/completion/CompletionItem", () => { /> ).root; const spans = root.findAllByType("span"); - expect(spans).to.have.lengthOf(2); - expect(spans[0].children).to.deep.equal(["twitter"]); - expect(spans[1].children).to.deep.equal(["https://twitter.com/"]); + expect(spans).toHaveLength(2); + expect(spans[0].children).toEqual(["twitter"]); + expect(spans[1].children).toEqual(["https://twitter.com/"]); }); }); diff --git a/test/console/components/console/CompletionTitle.test.tsx b/test/console/components/console/CompletionTitle.test.tsx index d8cc411..5843c43 100644 --- a/test/console/components/console/CompletionTitle.test.tsx +++ b/test/console/components/console/CompletionTitle.test.tsx @@ -1,6 +1,5 @@ import React from "react"; import ReactTestRenderer from "react-test-renderer"; -import { expect } from "chai"; import CompletionTitle from "../../../../src/console/components/console/CompletionTitle"; describe("console/components/console/completion/CompletionTitle", () => { @@ -10,6 +9,6 @@ describe("console/components/console/completion/CompletionTitle", () => { ).root; const li = root.findByType("li"); - expect(li.children).to.deep.equal(["Fruits"]); + expect(li.children).toEqual(["Fruits"]); }); }); diff --git a/test/content/InputDriver.test.ts b/test/content/InputDriver.test.ts index f464dac..9ab0965 100644 --- a/test/content/InputDriver.test.ts +++ b/test/content/InputDriver.test.ts @@ -1,7 +1,10 @@ +/** + * @jest-environment jsdom + */ + import InputDriver, { keyFromKeyboardEvent, } from "../../src/content/InputDriver"; -import { expect } from "chai"; import Key from "../../src/shared/settings/Key"; describe("InputDriver", () => { @@ -20,11 +23,11 @@ describe("InputDriver", () => { it("register callbacks", (done) => { driver.onKey((key: Key): boolean => { - expect(key.key).to.equal("a"); - expect(key.ctrl).to.be.true; - expect(key.shift).to.be.false; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("a"); + expect(key.ctrl).toBeTruthy; + expect(key.shift).toBeFalsy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; done(); return true; }); @@ -65,8 +68,8 @@ describe("InputDriver", () => { target.dispatchEvent(e); } - expect(a).to.equal(1); - expect(b).to.equal(1); + expect(a).toEqual(1); + expect(b).toEqual(1); }); it("propagates and stop handler chain", () => { @@ -88,14 +91,14 @@ describe("InputDriver", () => { target.dispatchEvent(new KeyboardEvent("keydown", { key: "b" })); - expect(a).to.equal(1); - expect(b).to.equal(1); - expect(c).to.equal(0); + expect(a).toEqual(1); + expect(b).toEqual(1); + expect(c).toEqual(0); }); it("does not invoke only meta keys", () => { driver.onKey((_key: Key): boolean => { - expect.fail(); + throw new Error("unexpected reach"); return false; }); @@ -110,7 +113,7 @@ describe("InputDriver", () => { const input = window.document.createElement(name); const driver = new InputDriver(input); driver.onKey((_key: Key): boolean => { - expect.fail(); + throw new Error("unexpected reach"); return false; }); input.dispatchEvent(new KeyboardEvent("keydown", { key: "x" })); @@ -121,7 +124,7 @@ describe("InputDriver", () => { const div = window.document.createElement("div"); const driver = new InputDriver(div); driver.onKey((_key: Key): boolean => { - expect.fail(); + throw new Error("unexpected reach"); return false; }); @@ -144,11 +147,11 @@ describe("#keyFromKeyboardEvent", () => { metaKey: true, }) ); - expect(k.key).to.equal("x"); - expect(k.shift).to.be.false; - expect(k.ctrl).to.be.true; - expect(k.alt).to.be.false; - expect(k.meta).to.be.true; + expect(k.key).toEqual("x"); + expect(k.shift).toBeFalsy; + expect(k.ctrl).toBeTruthy; + expect(k.alt).toBeFalsy; + expect(k.meta).toBeTruthy; }); it("returns from keyboard input Shift+Esc", () => { @@ -161,11 +164,11 @@ describe("#keyFromKeyboardEvent", () => { metaKey: true, }) ); - expect(k.key).to.equal("Esc"); - expect(k.shift).to.be.true; - expect(k.ctrl).to.be.false; - expect(k.alt).to.be.false; - expect(k.meta).to.be.true; + expect(k.key).toEqual("Esc"); + expect(k.shift).toBeTruthy; + expect(k.ctrl).toBeFalsy; + expect(k.alt).toBeFalsy; + expect(k.meta).toBeTruthy; }); it("returns from keyboard input Ctrl+$", () => { @@ -179,11 +182,11 @@ describe("#keyFromKeyboardEvent", () => { metaKey: false, }) ); - expect(k.key).to.equal("$"); - expect(k.shift).to.be.false; - expect(k.ctrl).to.be.true; - expect(k.alt).to.be.false; - expect(k.meta).to.be.false; + expect(k.key).toEqual("$"); + expect(k.shift).toBeFalsy; + expect(k.ctrl).toBeTruthy; + expect(k.alt).toBeFalsy; + expect(k.meta).toBeFalsy; }); it("returns from keyboard input Crtl+Space", () => { @@ -196,10 +199,10 @@ describe("#keyFromKeyboardEvent", () => { metaKey: false, }) ); - expect(k.key).to.equal("Space"); - expect(k.shift).to.be.false; - expect(k.ctrl).to.be.true; - expect(k.alt).to.be.false; - expect(k.meta).to.be.false; + expect(k.key).toEqual("Space"); + expect(k.shift).toBeFalsy; + expect(k.ctrl).toBeTruthy; + expect(k.alt).toBeFalsy; + expect(k.meta).toBeFalsy; }); }); diff --git a/test/content/domains/KeySequence.test.ts b/test/content/domains/KeySequence.test.ts index 1d1debe..683f592 100644 --- a/test/content/domains/KeySequence.test.ts +++ b/test/content/domains/KeySequence.test.ts @@ -1,5 +1,4 @@ import KeySequence from "../../../src/content/domains/KeySequence"; -import { expect } from "chai"; import Key from "../../../src/shared/settings/Key"; describe("KeySequence", () => { @@ -9,9 +8,9 @@ describe("KeySequence", () => { seq.push(Key.fromMapKey("g")); seq.push(Key.fromMapKey("<S-U>")); - expect(seq.keys[0].key).to.equal("g"); - expect(seq.keys[1].key).to.equal("U"); - expect(seq.keys[1].shift).to.be.true; + expect(seq.keys[0].key).toEqual("g"); + expect(seq.keys[1].key).toEqual("U"); + expect(seq.keys[1].shift).toBeTruthy; }); }); @@ -22,13 +21,13 @@ describe("KeySequence", () => { Key.fromMapKey("<S-U>"), ]); - expect(seq.startsWith(new KeySequence([]))).to.be.true; - expect(seq.startsWith(new KeySequence([Key.fromMapKey("g")]))).to.be.true; + expect(seq.startsWith(new KeySequence([]))).toBeTruthy; + expect(seq.startsWith(new KeySequence([Key.fromMapKey("g")]))).toBeTruthy; expect( seq.startsWith( new KeySequence([Key.fromMapKey("g"), Key.fromMapKey("<S-U>")]) ) - ).to.be.true; + ).toBeTruthy; expect( seq.startsWith( new KeySequence([ @@ -37,17 +36,15 @@ describe("KeySequence", () => { Key.fromMapKey("x"), ]) ) - ).to.be.false; - expect(seq.startsWith(new KeySequence([Key.fromMapKey("h")]))).to.be - .false; + ).toBeFalsy; + expect(seq.startsWith(new KeySequence([Key.fromMapKey("h")]))).toBeFalsy; }); it("returns true if the empty sequence starts with an empty sequence", () => { const seq = new KeySequence([]); - expect(seq.startsWith(new KeySequence([]))).to.be.true; - expect(seq.startsWith(new KeySequence([Key.fromMapKey("h")]))).to.be - .false; + expect(seq.startsWith(new KeySequence([]))).toBeTruthy; + expect(seq.startsWith(new KeySequence([Key.fromMapKey("h")]))).toBeFalsy; }); }); @@ -58,14 +55,14 @@ describe("KeySequence", () => { new Key({ key: "4" }), new Key({ key: "0" }), ]).isDigitOnly() - ).to.be.true; + ).toBeTruthy; expect( new KeySequence([ new Key({ key: "4" }), new Key({ key: "0" }), new Key({ key: "z" }), ]).isDigitOnly() - ).to.be.false; + ).toBeFalsy; }); }); @@ -77,7 +74,7 @@ describe("KeySequence", () => { new Key({ key: "g" }), new Key({ key: "g" }), ]); - expect(seq.repeatCount()).to.equal(10); + expect(seq.repeatCount()).toEqual(10); seq = new KeySequence([ new Key({ key: "0" }), @@ -85,23 +82,23 @@ describe("KeySequence", () => { new Key({ key: "g" }), new Key({ key: "g" }), ]); - expect(seq.repeatCount()).to.equal(5); + expect(seq.repeatCount()).toEqual(5); }); it("returns 1 if no numeric prefix", () => { let seq = new KeySequence([new Key({ key: "g" }), new Key({ key: "g" })]); - expect(seq.repeatCount()).to.equal(1); + expect(seq.repeatCount()).toEqual(1); seq = new KeySequence([]); - expect(seq.repeatCount()).to.equal(1); + expect(seq.repeatCount()).toEqual(1); }); it("returns whole keys if digits only sequence", () => { let seq = new KeySequence([new Key({ key: "1" }), new Key({ key: "0" })]); - expect(seq.repeatCount()).to.equal(10); + expect(seq.repeatCount()).toEqual(10); seq = new KeySequence([new Key({ key: "0" }), new Key({ key: "5" })]); - expect(seq.repeatCount()).to.equal(5); + expect(seq.repeatCount()).toEqual(5); }); }); @@ -114,7 +111,7 @@ describe("KeySequence", () => { new Key({ key: "g" }), new Key({ key: "3" }), ]).trimNumericPrefix(); - expect(seq.keys.map((key) => key.key)).to.deep.equal(["g", "g", "3"]); + expect(seq.keys.map((key) => key.key)).toEqual(["g", "g", "3"]); }); it("returns empty if keys contains only digis", () => { @@ -122,7 +119,7 @@ describe("KeySequence", () => { new Key({ key: "1" }), new Key({ key: "0" }), ]).trimNumericPrefix(); - expect(seq.trimNumericPrefix().keys).to.be.empty; + expect(seq.trimNumericPrefix().keys).toHaveLength(0); }); it("returns itself if no numeric prefix", () => { @@ -132,23 +129,21 @@ describe("KeySequence", () => { new Key({ key: "3" }), ]).trimNumericPrefix(); - expect(seq.keys.map((key) => key.key)).to.deep.equal(["g", "g", "3"]); + expect(seq.keys.map((key) => key.key)).toEqual(["g", "g", "3"]); }); }); describe("#splitNumericPrefix", () => { it("splits numeric prefix", () => { - expect( - KeySequence.fromMapKeys("10gg").splitNumericPrefix() - ).to.deep.equal([ + expect(KeySequence.fromMapKeys("10gg").splitNumericPrefix()).toEqual([ KeySequence.fromMapKeys("10"), KeySequence.fromMapKeys("gg"), ]); - expect(KeySequence.fromMapKeys("10").splitNumericPrefix()).to.deep.equal([ + expect(KeySequence.fromMapKeys("10").splitNumericPrefix()).toEqual([ KeySequence.fromMapKeys("10"), new KeySequence([]), ]); - expect(KeySequence.fromMapKeys("gg").splitNumericPrefix()).to.deep.equal([ + expect(KeySequence.fromMapKeys("gg").splitNumericPrefix()).toEqual([ new KeySequence([]), KeySequence.fromMapKeys("gg"), ]); @@ -158,22 +153,22 @@ describe("KeySequence", () => { describe("#fromMapKeys", () => { it("returns mapped keys for Shift+Esc", () => { const keys = KeySequence.fromMapKeys("<S-Esc>").keys; - expect(keys).to.have.lengthOf(1); - expect(keys[0].key).to.equal("Esc"); - expect(keys[0].shift).to.be.true; + expect(keys).toHaveLength(1); + expect(keys[0].key).toEqual("Esc"); + expect(keys[0].shift).toBeTruthy; }); it("returns mapped keys for a<C-B><A-C>d<M-e>", () => { const keys = KeySequence.fromMapKeys("a<C-B><A-C>d<M-e>").keys; - expect(keys).to.have.lengthOf(5); - expect(keys[0].key).to.equal("a"); - expect(keys[1].ctrl).to.be.true; - expect(keys[1].key).to.equal("b"); - expect(keys[2].alt).to.be.true; - expect(keys[2].key).to.equal("c"); - expect(keys[3].key).to.equal("d"); - expect(keys[4].meta).to.be.true; - expect(keys[4].key).to.equal("e"); + expect(keys).toHaveLength(5); + expect(keys[0].key).toEqual("a"); + expect(keys[1].ctrl).toBeTruthy; + expect(keys[1].key).toEqual("b"); + expect(keys[2].alt).toBeTruthy; + expect(keys[2].key).toEqual("c"); + expect(keys[3].key).toEqual("d"); + expect(keys[4].meta).toBeTruthy; + expect(keys[4].key).toEqual("e"); }); }); }); diff --git a/test/content/operators/impls/AddonOperatorFactoryChain.test.ts b/test/content/operators/impls/AddonOperatorFactoryChain.test.ts index dde5a35..263104e 100644 --- a/test/content/operators/impls/AddonOperatorFactoryChain.test.ts +++ b/test/content/operators/impls/AddonOperatorFactoryChain.test.ts @@ -3,7 +3,6 @@ import EnableAddonOperator from "../../../../src/content/operators/impls/EnableA import DisableAddonOperator from "../../../../src/content/operators/impls/DisableAddonOperator"; import ToggleAddonOperator from "../../../../src/content/operators/impls/ToggleAddonOperator"; import * as operations from "../../../../src/shared/operations"; -import { expect } from "chai"; import MockAddonIndicatorClient from "../../mock/MockAddonIndicatorClient"; import MockAddonEnabledRepository from "../../mock/MockAddonEnabledRepository"; import MockConsoleFramePresenter from "./MockConsoleFramePresenter"; @@ -16,16 +15,16 @@ describe("AddonOperatorFactoryChain", () => { new MockAddonEnabledRepository(), new MockConsoleFramePresenter(false) ); - expect(sut.create({ type: operations.ADDON_ENABLE }, 0)).to.be.instanceOf( + expect(sut.create({ type: operations.ADDON_ENABLE }, 0)).toBeInstanceOf( EnableAddonOperator ); - expect( - sut.create({ type: operations.ADDON_DISABLE }, 0) - ).to.be.instanceOf(DisableAddonOperator); + expect(sut.create({ type: operations.ADDON_DISABLE }, 0)).toBeInstanceOf( + DisableAddonOperator + ); expect( sut.create({ type: operations.ADDON_TOGGLE_ENABLED }, 0) - ).to.be.instanceOf(ToggleAddonOperator); - expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.null; + ).toBeInstanceOf(ToggleAddonOperator); + expect(sut.create({ type: operations.SCROLL_TOP }, 0)).toBeNull; }); }); }); diff --git a/test/content/operators/impls/BackgroundOperationOperator.test.ts b/test/content/operators/impls/BackgroundOperationOperator.test.ts index b8b1fbd..77efeb2 100644 --- a/test/content/operators/impls/BackgroundOperationOperator.test.ts +++ b/test/content/operators/impls/BackgroundOperationOperator.test.ts @@ -1,7 +1,6 @@ import * as operations from "../../../../src/shared/operations"; import BackgroundOperationOperator from "../../../../src/content/operators/impls/BackgroundOperationOperator"; import OperationClient from "../../../../src/content/client/OperationClient"; -import { expect } from "chai"; class MockOperationClient implements OperationClient { public readonly executedOps: { @@ -30,7 +29,7 @@ describe("BackgroundOperationOperator", () => { await sut.run(); - expect(client.executedOps).to.deep.equal([ + expect(client.executedOps).toEqual([ { op: { type: operations.TAB_CLOSE }, repeat: 2 }, ]); }); diff --git a/test/content/operators/impls/ClipboardOperatorFactoryChain.test.ts b/test/content/operators/impls/ClipboardOperatorFactoryChain.test.ts index 9ddc229..d4c61c4 100644 --- a/test/content/operators/impls/ClipboardOperatorFactoryChain.test.ts +++ b/test/content/operators/impls/ClipboardOperatorFactoryChain.test.ts @@ -1,5 +1,4 @@ import * as operations from "../../../../src/shared/operations"; -import { expect } from "chai"; import ClipboardOperatorFactoryChain from "../../../../src/content/operators/impls/ClipboardOperatorFactoryChain"; import YankURLOperator from "../../../../src/content/operators/impls/YankURLOperator"; import PasteOperator from "../../../../src/content/operators/impls/PasteOperator"; @@ -19,13 +18,13 @@ describe("ClipboardOperatorFactoryChain", () => { new MockSettingRepository(), new MockURLRepository() ); - expect(sut.create({ type: operations.URLS_YANK }, 0)).to.be.instanceOf( + expect(sut.create({ type: operations.URLS_YANK }, 0)).toBeInstanceOf( YankURLOperator ); expect( sut.create({ type: operations.URLS_PASTE, newTab: false }, 0) - ).to.be.instanceOf(PasteOperator); - expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.null; + ).toBeInstanceOf(PasteOperator); + expect(sut.create({ type: operations.SCROLL_TOP }, 0)).toBeNull; }); }); }); diff --git a/test/content/operators/impls/DisableAddonOperator.test.ts b/test/content/operators/impls/DisableAddonOperator.test.ts index e05d1f1..bb137ac 100644 --- a/test/content/operators/impls/DisableAddonOperator.test.ts +++ b/test/content/operators/impls/DisableAddonOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import DisableAddonOperator from "../../../../src/content/operators/impls/DisableAddonOperator"; import MockAddonIndicatorClient from "../../mock/MockAddonIndicatorClient"; import MockAddonEnabledRepository from "../../mock/MockAddonEnabledRepository"; @@ -14,9 +13,9 @@ describe("DisableAddonOperator", () => { await sut.run(); - expect(client.enabled).to.be.false; - expect(repository.enabled).to.be.false; - expect(presenter.attached).to.be.false; + expect(client.enabled).toBeFalsy; + expect(repository.enabled).toBeFalsy; + expect(presenter.attached).toBeFalsy; }); }); }); diff --git a/test/content/operators/impls/EnableAddonOperator.test.ts b/test/content/operators/impls/EnableAddonOperator.test.ts index 6025608..cd838af 100644 --- a/test/content/operators/impls/EnableAddonOperator.test.ts +++ b/test/content/operators/impls/EnableAddonOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import EnableAddonOperator from "../../../../src/content/operators/impls/EnableAddonOperator"; import MockAddonIndicatorClient from "../../mock/MockAddonIndicatorClient"; import MockAddonEnabledRepository from "../../mock/MockAddonEnabledRepository"; @@ -14,9 +13,9 @@ describe("EnableAddonOperator", () => { await sut.run(); - expect(client.enabled).to.be.true; - expect(repository.enabled).to.be.true; - expect(presenter.attached).to.be.true; + expect(client.enabled).toBeTruthy; + expect(repository.enabled).toBeTruthy; + expect(presenter.attached).toBeTruthy; }); }); }); diff --git a/test/content/operators/impls/EnableJumpMarkOperator.test.ts b/test/content/operators/impls/EnableJumpMarkOperator.test.ts index 66b4ecd..f81d6dc 100644 --- a/test/content/operators/impls/EnableJumpMarkOperator.test.ts +++ b/test/content/operators/impls/EnableJumpMarkOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import EnableJumpMarkOperator from "../../../../src/content/operators/impls/EnableJumpMarkOperator"; import MockMarkKeyRepository from "../../mock/MockMarkKeyRepository"; @@ -13,7 +12,7 @@ describe("EnableJumpMarkOperator", () => { await sut.run(); - expect(repository.jumpMode).to.be.true; + expect(repository.jumpMode).toBeTruthy; }); }); }); diff --git a/test/content/operators/impls/EnableSetMarkOperator.test.ts b/test/content/operators/impls/EnableSetMarkOperator.test.ts index b28874d..33ce2ba 100644 --- a/test/content/operators/impls/EnableSetMarkOperator.test.ts +++ b/test/content/operators/impls/EnableSetMarkOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import EnableSetMarkOperator from "../../../../src/content/operators/impls/EnableSetMarkOperator"; import MockMarkKeyRepository from "../../mock/MockMarkKeyRepository"; @@ -13,7 +12,7 @@ describe("EnableSetMarkOperator", () => { await sut.run(); - expect(repository.setMode).to.be.true; + expect(repository.setMode).toBeTruthy; }); }); }); diff --git a/test/content/operators/impls/FocusOperator.test.ts b/test/content/operators/impls/FocusOperator.test.ts index a0eb53b..2d72620 100644 --- a/test/content/operators/impls/FocusOperator.test.ts +++ b/test/content/operators/impls/FocusOperator.test.ts @@ -1,4 +1,3 @@ -import sinon from "sinon"; import FocusOperator from "../../../../src/content/operators/impls/FocusOperator"; import MockFocusPresenter from "../../mock/MockFocusPresenter"; @@ -6,12 +5,14 @@ describe("FocusOperator", () => { describe("#run", () => { it("focus a first input", async () => { const presenter = new MockFocusPresenter(); - const mock = sinon.mock(presenter).expects("focusFirstElement"); + const focusFirstElementSpy = jest + .spyOn(presenter, "focusFirstElement") + .mockReturnValue(true); const sut = new FocusOperator(presenter); await sut.run(); - mock.verify(); + expect(focusFirstElementSpy).toBeCalled(); }); }); }); diff --git a/test/content/operators/impls/FocusOperatorFactoryChain.test.ts b/test/content/operators/impls/FocusOperatorFactoryChain.test.ts index 91f734b..84a4a52 100644 --- a/test/content/operators/impls/FocusOperatorFactoryChain.test.ts +++ b/test/content/operators/impls/FocusOperatorFactoryChain.test.ts @@ -1,5 +1,4 @@ import * as operations from "../../../../src/shared/operations"; -import { expect } from "chai"; import FocusOperatorFactoryChain from "../../../../src/content/operators/impls/FocusOperatorFactoryChain"; import FocusOperator from "../../../../src/content/operators/impls/FocusOperator"; import MockFocusPresenter from "../../mock/MockFocusPresenter"; @@ -8,10 +7,10 @@ describe("FocusOperatorFactoryChain", () => { describe("#create", () => { it("returns an operator", () => { const sut = new FocusOperatorFactoryChain(new MockFocusPresenter()); - expect(sut.create({ type: operations.FOCUS_INPUT }, 0)).to.be.instanceOf( + expect(sut.create({ type: operations.FOCUS_INPUT }, 0)).toBeInstanceOf( FocusOperator ); - expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.null; + expect(sut.create({ type: operations.SCROLL_TOP }, 0)).toBeNull; }); }); }); diff --git a/test/content/operators/impls/FollowOperatorFactoryChain.test.ts b/test/content/operators/impls/FollowOperatorFactoryChain.test.ts index 526a93c..84a4a52 100644 --- a/test/content/operators/impls/FollowOperatorFactoryChain.test.ts +++ b/test/content/operators/impls/FollowOperatorFactoryChain.test.ts @@ -1,5 +1,4 @@ import * as operations from "../../../../src/shared/operations"; -import { expect } from "chai"; import FocusOperatorFactoryChain from "../../../../src/content/operators/impls/FocusOperatorFactoryChain"; import FocusOperator from "../../../../src/content/operators/impls/FocusOperator"; import MockFocusPresenter from "../../mock/MockFocusPresenter"; @@ -8,13 +7,10 @@ describe("FocusOperatorFactoryChain", () => { describe("#create", () => { it("returns an operator", () => { const sut = new FocusOperatorFactoryChain(new MockFocusPresenter()); - expect( - sut.create( - { type: operations.FOCUS_INPUT, newTab: false, background: false }, - 0 - ) - ).to.be.instanceOf(FocusOperator); - expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.null; + expect(sut.create({ type: operations.FOCUS_INPUT }, 0)).toBeInstanceOf( + FocusOperator + ); + expect(sut.create({ type: operations.SCROLL_TOP }, 0)).toBeNull; }); }); }); diff --git a/test/content/operators/impls/HorizontalScrollOperator.test.ts b/test/content/operators/impls/HorizontalScrollOperator.test.ts index f77a34e..abe6856 100644 --- a/test/content/operators/impls/HorizontalScrollOperator.test.ts +++ b/test/content/operators/impls/HorizontalScrollOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import HorizontalScrollOperator from "../../../../src/content/operators/impls/HorizontalScrollOperator"; import MockScrollPresenter from "../../mock/MockScrollPresenter"; import MockSettingRepository from "../../mock/MockSettingRepository"; @@ -12,7 +11,7 @@ describe("HorizontalScrollOperator", () => { await sut.run(); - expect(presenter.getScroll()).to.deep.equal({ x: 1, y: 0 }); + expect(presenter.getScroll()).toEqual({ x: 1, y: 0 }); }); it("scroll horizontally with repeats", async () => { @@ -22,7 +21,7 @@ describe("HorizontalScrollOperator", () => { await sut.run(); - expect(presenter.getScroll()).to.deep.equal({ x: 5, y: 0 }); + expect(presenter.getScroll()).toEqual({ x: 5, y: 0 }); }); }); }); diff --git a/test/content/operators/impls/MarkOperatorFactoryChain.test.ts b/test/content/operators/impls/MarkOperatorFactoryChain.test.ts index 1f094dd..99cb756 100644 --- a/test/content/operators/impls/MarkOperatorFactoryChain.test.ts +++ b/test/content/operators/impls/MarkOperatorFactoryChain.test.ts @@ -1,5 +1,4 @@ import * as operations from "../../../../src/shared/operations"; -import { expect } from "chai"; import MarkOperatorFactoryChain from "../../../../src/content/operators/impls/MarkOperatorFactoryChain"; import MockMarkKeyRepository from "../../mock/MockMarkKeyRepository"; import EnableSetMarkOperator from "../../../../src/content/operators/impls/EnableSetMarkOperator"; @@ -11,11 +10,11 @@ describe("MarkOperatorFactoryChain", () => { const sut = new MarkOperatorFactoryChain(new MockMarkKeyRepository()); expect( sut.create({ type: operations.MARK_SET_PREFIX }, 0) - ).to.be.instanceOf(EnableSetMarkOperator); + ).toBeInstanceOf(EnableSetMarkOperator); expect( sut.create({ type: operations.MARK_JUMP_PREFIX }, 0) - ).to.be.instanceOf(EnableJumpMarkOperator); - expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.null; + ).toBeInstanceOf(EnableJumpMarkOperator); + expect(sut.create({ type: operations.SCROLL_TOP }, 0)).toBeNull; }); }); }); diff --git a/test/content/operators/impls/PageScrollOperator.test.ts b/test/content/operators/impls/PageScrollOperator.test.ts index 80c9185..77d3a0f 100644 --- a/test/content/operators/impls/PageScrollOperator.test.ts +++ b/test/content/operators/impls/PageScrollOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import PageScrollOperator from "../../../../src/content/operators/impls/PageScrollOperator"; import MockScrollPresenter from "../../mock/MockScrollPresenter"; import MockSettingRepository from "../../mock/MockSettingRepository"; @@ -12,7 +11,7 @@ describe("PageScrollOperator", () => { await sut.run(); - expect(presenter.getScroll()).to.deep.equal({ x: 1, y: 0 }); + expect(presenter.getScroll()).toEqual({ x: 1, y: 0 }); }); it("scroll by a page with repeats", async () => { @@ -22,7 +21,7 @@ describe("PageScrollOperator", () => { await sut.run(); - expect(presenter.getScroll()).to.deep.equal({ x: 5, y: 0 }); + expect(presenter.getScroll()).toEqual({ x: 5, y: 0 }); }); }); }); diff --git a/test/content/operators/impls/PasteOperator.test.ts b/test/content/operators/impls/PasteOperator.test.ts index 8a3a374..fa42576 100644 --- a/test/content/operators/impls/PasteOperator.test.ts +++ b/test/content/operators/impls/PasteOperator.test.ts @@ -1,4 +1,3 @@ -import sinon from "sinon"; import PasteOperator from "../../../../src/content/operators/impls/PasteOperator"; import MockClipboardRepository from "../../mock/MockClipboardRepository"; import MockSettingRepository from "../../mock/MockSettingRepository"; @@ -10,10 +9,9 @@ describe("PasteOperator", () => { const clipboardRepository = new MockClipboardRepository("apple"); const settingRepository = new MockSettingRepository(); const operationClient = new MockOperationClient(); - const mockOperationClient = sinon - .mock(operationClient) - .expects("internalOpenUrl") - .withArgs("https://google.com/search?q=apple"); + const internalOpenUrlSpy = jest + .spyOn(operationClient, "internalOpenUrl") + .mockReturnValue(Promise.resolve()); const sut = new PasteOperator( clipboardRepository, settingRepository, @@ -23,7 +21,10 @@ describe("PasteOperator", () => { await sut.run(); - mockOperationClient.verify(); + expect(internalOpenUrlSpy).toBeCalledWith( + "https://google.com/search?q=apple", + false + ); }); it("open a url", async () => { @@ -32,10 +33,9 @@ describe("PasteOperator", () => { ); const settingRepository = new MockSettingRepository(); const operationClient = new MockOperationClient(); - const mockOperationClient = sinon - .mock(operationClient) - .expects("internalOpenUrl") - .withArgs("https://example.com/"); + const internalOpenUrlSpy = jest + .spyOn(operationClient, "internalOpenUrl") + .mockReturnValue(Promise.resolve()); const sut = new PasteOperator( clipboardRepository, settingRepository, @@ -45,7 +45,7 @@ describe("PasteOperator", () => { await sut.run(); - mockOperationClient.verify(); + expect(internalOpenUrlSpy).toBeCalledWith("https://example.com/", false); }); }); }); diff --git a/test/content/operators/impls/ScrollOperatorFactoryChain.test.ts b/test/content/operators/impls/ScrollOperatorFactoryChain.test.ts index 08034cb..3ba204a 100644 --- a/test/content/operators/impls/ScrollOperatorFactoryChain.test.ts +++ b/test/content/operators/impls/ScrollOperatorFactoryChain.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import ScrollOperatorFactoryChain from "../../../../src/content/operators/impls/ScrollOperatorFactoryChain"; import MockScrollPresenter from "../../mock/MockScrollPresenter"; import MockSettingRepository from "../../mock/MockSettingRepository"; @@ -20,27 +19,27 @@ describe("ScrollOperatorFactoryChain", () => { ); expect( sut.create({ type: operations.SCROLL_HORIZONALLY, count: 10 }, 0) - ).to.be.instanceOf(HorizontalScrollOperator); + ).toBeInstanceOf(HorizontalScrollOperator); expect( sut.create({ type: operations.SCROLL_VERTICALLY, count: 10 }, 0) - ).to.be.instanceOf(VerticalScrollOperator); + ).toBeInstanceOf(VerticalScrollOperator); expect( sut.create({ type: operations.SCROLL_PAGES, count: 10 }, 0) - ).to.be.instanceOf(PageScrollOperator); - expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.instanceOf( + ).toBeInstanceOf(PageScrollOperator); + expect(sut.create({ type: operations.SCROLL_TOP }, 0)).toBeInstanceOf( ScrollToTopOperator ); - expect( - sut.create({ type: operations.SCROLL_BOTTOM }, 0) - ).to.be.instanceOf(ScrollToBottomOperator); - expect(sut.create({ type: operations.SCROLL_HOME }, 0)).to.be.instanceOf( + expect(sut.create({ type: operations.SCROLL_BOTTOM }, 0)).toBeInstanceOf( + ScrollToBottomOperator + ); + expect(sut.create({ type: operations.SCROLL_HOME }, 0)).toBeInstanceOf( ScrollToHomeOperator ); - expect(sut.create({ type: operations.SCROLL_END }, 0)).to.be.instanceOf( + expect(sut.create({ type: operations.SCROLL_END }, 0)).toBeInstanceOf( ScrollToEndOperator ); - expect(sut.create({ type: operations.PAGE_HOME, newTab: false }, 0)).to.be - .null; + expect(sut.create({ type: operations.PAGE_HOME, newTab: false }, 0)) + .toBeNull; }); }); }); diff --git a/test/content/operators/impls/ScrollToBottomOperator.test.ts b/test/content/operators/impls/ScrollToBottomOperator.test.ts index 500c8f2..f369227 100644 --- a/test/content/operators/impls/ScrollToBottomOperator.test.ts +++ b/test/content/operators/impls/ScrollToBottomOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import ScrollToBottomOperator from "../../../../src/content/operators/impls/ScrollToBottomOperator"; import MockScrollPresenter from "../../mock/MockScrollPresenter"; import MockSettingRepository from "../../mock/MockSettingRepository"; @@ -12,7 +11,7 @@ describe("ScrollToBottomOperator", () => { await sut.run(); - expect(presenter.getScroll()).to.deep.equal({ x: 0, y: Infinity }); + expect(presenter.getScroll()).toEqual({ x: 0, y: Infinity }); }); }); }); diff --git a/test/content/operators/impls/ScrollToEndOperator.test.ts b/test/content/operators/impls/ScrollToEndOperator.test.ts index 0c98c8d..304d914 100644 --- a/test/content/operators/impls/ScrollToEndOperator.test.ts +++ b/test/content/operators/impls/ScrollToEndOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import ScrollToEndOperator from "../../../../src/content/operators/impls/ScrollToEndOperator"; import MockScrollPresenter from "../../mock/MockScrollPresenter"; import MockSettingRepository from "../../mock/MockSettingRepository"; @@ -12,7 +11,7 @@ describe("ScrollToEndOperator", () => { await sut.run(); - expect(presenter.getScroll()).to.deep.equal({ x: Infinity, y: 0 }); + expect(presenter.getScroll()).toEqual({ x: Infinity, y: 0 }); }); }); }); diff --git a/test/content/operators/impls/ScrollToHomeOperator.test.ts b/test/content/operators/impls/ScrollToHomeOperator.test.ts index f8614d2..e09c16a 100644 --- a/test/content/operators/impls/ScrollToHomeOperator.test.ts +++ b/test/content/operators/impls/ScrollToHomeOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import ScrollToHomeOperator from "../../../../src/content/operators/impls/ScrollToHomeOperator"; import MockScrollPresenter from "../../mock/MockScrollPresenter"; import MockSettingRepository from "../../mock/MockSettingRepository"; @@ -12,7 +11,7 @@ describe("ScrollToHomeOperator", () => { await sut.run(); - expect(presenter.getScroll()).to.deep.equal({ x: 0, y: 10 }); + expect(presenter.getScroll()).toEqual({ x: 0, y: 10 }); }); }); }); diff --git a/test/content/operators/impls/ScrollToTopOperator.test.ts b/test/content/operators/impls/ScrollToTopOperator.test.ts index 25a84ba..7337bea 100644 --- a/test/content/operators/impls/ScrollToTopOperator.test.ts +++ b/test/content/operators/impls/ScrollToTopOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import ScrollToTopOperator from "../../../../src/content/operators/impls/ScrollToTopOperator"; import MockScrollPresenter from "../../mock/MockScrollPresenter"; import MockSettingRepository from "../../mock/MockSettingRepository"; @@ -12,7 +11,7 @@ describe("ScrollToTopOperator", () => { await sut.run(); - expect(presenter.getScroll()).to.deep.equal({ x: 10, y: 0 }); + expect(presenter.getScroll()).toEqual({ x: 10, y: 0 }); }); }); }); diff --git a/test/content/operators/impls/StartFollowOperator.test.ts b/test/content/operators/impls/StartFollowOperator.test.ts index 8f9bd2d..4216cd0 100644 --- a/test/content/operators/impls/StartFollowOperator.test.ts +++ b/test/content/operators/impls/StartFollowOperator.test.ts @@ -1,4 +1,3 @@ -import sinon from "sinon"; import StartFollowOperator from "../../../../src/content/operators/impls/StartFollowOperator"; import MockFollowMasterClient from "../../mock/MockFollowMasterClient"; @@ -6,15 +5,14 @@ describe("StartFollowOperator", () => { describe("#run", () => { it("starts following links", async () => { const client = new MockFollowMasterClient(); - const mock = sinon - .mock(client) - .expects("startFollow") - .withArgs(true, false); + const startFollowSpy = jest + .spyOn(client, "startFollow") + .mockReturnValue(); const sut = new StartFollowOperator(client, true, false); await sut.run(); - mock.verify(); + expect(startFollowSpy).toBeCalledWith(true, false); }); }); }); diff --git a/test/content/operators/impls/ToggleAddonOperator.test.ts b/test/content/operators/impls/ToggleAddonOperator.test.ts index 1f291b5..cc77429 100644 --- a/test/content/operators/impls/ToggleAddonOperator.test.ts +++ b/test/content/operators/impls/ToggleAddonOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import ToggleAddonOperator from "../../../../src/content/operators/impls/ToggleAddonOperator"; import MockAddonIndicatorClient from "../../mock/MockAddonIndicatorClient"; import MockAddonEnabledRepository from "../../mock/MockAddonEnabledRepository"; @@ -14,15 +13,15 @@ describe("ToggleAddonOperator", () => { await sut.run(); - expect(client.enabled).to.be.false; - expect(repository.enabled).to.be.false; - expect(presenter.attached).to.be.false; + expect(client.enabled).toBeFalsy; + expect(repository.enabled).toBeFalsy; + expect(presenter.attached).toBeFalsy; await sut.run(); - expect(client.enabled).to.be.true; - expect(repository.enabled).to.be.true; - expect(presenter.attached).to.be.true; + expect(client.enabled).toBeTruthy; + expect(repository.enabled).toBeTruthy; + expect(presenter.attached).toBeTruthy; }); }); }); diff --git a/test/content/operators/impls/VerticalScrollOperator.test.ts b/test/content/operators/impls/VerticalScrollOperator.test.ts index 05b15d2..1b87060 100644 --- a/test/content/operators/impls/VerticalScrollOperator.test.ts +++ b/test/content/operators/impls/VerticalScrollOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import VerticalScrollOperator from "../../../../src/content/operators/impls/VerticalScrollOperator"; import MockScrollPresenter from "../../mock/MockScrollPresenter"; import MockSettingRepository from "../../mock/MockSettingRepository"; @@ -12,7 +11,7 @@ describe("VerticalScrollOperator", () => { await sut.run(); - expect(presenter.getScroll()).to.deep.equal({ x: 0, y: 1 }); + expect(presenter.getScroll()).toEqual({ x: 0, y: 1 }); }); it("scroll vertically with repeats", async () => { @@ -22,7 +21,7 @@ describe("VerticalScrollOperator", () => { await sut.run(); - expect(presenter.getScroll()).to.deep.equal({ x: 0, y: 5 }); + expect(presenter.getScroll()).toEqual({ x: 0, y: 5 }); }); }); }); diff --git a/test/content/operators/impls/YankURLOperator.test.ts b/test/content/operators/impls/YankURLOperator.test.ts index 46e3d06..3db28bf 100644 --- a/test/content/operators/impls/YankURLOperator.test.ts +++ b/test/content/operators/impls/YankURLOperator.test.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import MockClipboardRepository from "../../mock/MockClipboardRepository"; import YankURLOperator from "../../../../src/content/operators/impls/YankURLOperator"; import MockURLRepository from "../../mock/MockURLRepository"; @@ -18,9 +17,9 @@ describe("YankOperation", () => { await sut.run(); - expect(clipboardRepository.read()).to.equal("https://example.com/"); - expect(consoleClient.text).to.equal("Yanked https://example.com/"); - expect(consoleClient.isError).to.be.false; + expect(clipboardRepository.read()).toEqual("https://example.com/"); + expect(consoleClient.text).toEqual("Yanked https://example.com/"); + expect(consoleClient.isError).toBeFalsy; }); }); }); diff --git a/test/content/presenters/Hint.test.html b/test/content/presenters/Hint.test.html deleted file mode 100644 index b50c5fe..0000000 --- a/test/content/presenters/Hint.test.html +++ /dev/null @@ -1 +0,0 @@ -<a id='test-link' href='javascript:window.vimvixenTest="hello"' >link</a> diff --git a/test/content/presenters/Hint.test.ts b/test/content/presenters/Hint.test.ts index 1a7c868..b3b2d19 100644 --- a/test/content/presenters/Hint.test.ts +++ b/test/content/presenters/Hint.test.ts @@ -1,8 +1,11 @@ +/** + * @jest-environment jsdom + */ + import AbstractHint, { LinkHint, InputHint, } from "../../../src/content/presenters/Hint"; -import { expect } from "chai"; class Hint extends AbstractHint {} @@ -17,7 +20,7 @@ describe("Hint", () => { new Hint(link, "abc"); const elem = document.querySelector(".vimvixen-hint"); - expect(elem!.textContent!.trim()).to.be.equal("abc"); + expect(elem!.textContent!.trim()).toEqual("abc"); }); }); @@ -29,7 +32,7 @@ describe("Hint", () => { hint.show(); const elem = document.querySelector(".vimvixen-hint") as HTMLElement; - expect(elem.style.display).to.not.equal("none"); + expect(elem.style.display).not.toEqual("none"); }); }); @@ -40,7 +43,7 @@ describe("Hint", () => { hint.hide(); const elem = document.querySelector(".vimvixen-hint") as HTMLElement; - expect(elem.style.display).to.equal("none"); + expect(elem.style.display).toEqual("none"); }); }); @@ -50,9 +53,9 @@ describe("Hint", () => { const hint = new Hint(link, "abc"); const elem = document.querySelector(".vimvixen-hint")!; - expect(elem.parentElement).to.not.be.null; + expect(elem.parentElement).not.toBeNull; hint.remove(); - expect(elem.parentElement).to.be.null; + expect(elem.parentElement).toBeNull; }); }); }); @@ -71,7 +74,7 @@ describe("LinkHint", () => { const link = document.getElementById("test-link1") as HTMLAnchorElement; const hint = new LinkHint(link, "abc"); - expect(hint.getLink()).to.equal("https://google.com/"); + expect(hint.getLink()).toEqual("https://google.com/"); }); }); @@ -80,12 +83,12 @@ describe("LinkHint", () => { let link = document.getElementById("test-link1") as HTMLAnchorElement; let hint = new LinkHint(link, "abc"); - expect(hint.getLinkTarget()).to.be.null; + expect(hint.getLinkTarget()).toBeNull; link = document.getElementById("test-link2") as HTMLAnchorElement; hint = new LinkHint(link, "abc"); - expect(hint.getLinkTarget()).to.equal("_blank"); + expect(hint.getLinkTarget()).toEqual("_blank"); }); }); @@ -104,7 +107,7 @@ describe("LinkHint", () => { describe("InputHint", () => { describe("#activate()", () => { - context("<input>", () => { + describe("<input>", () => { beforeEach(() => { document.body.innerHTML = `<input id='test-input'></input>`; }); @@ -114,11 +117,11 @@ describe("InputHint", () => { const hint = new InputHint(input, "abc"); hint.activate(); - expect(document.activeElement).to.equal(input); + expect(document.activeElement).toEqual(input); }); }); - context('<input type="checkbox">', () => { + describe('<input type="checkbox">', () => { beforeEach(() => { document.body.innerHTML = `<input type="checkbox" id='test-input'></input>`; }); @@ -128,10 +131,10 @@ describe("InputHint", () => { const hint = new InputHint(input, "abc"); hint.activate(); - expect(input.checked).to.be.true; + expect(input.checked).toBeTruthy; }); }); - context("<textarea>", () => { + describe("<textarea>", () => { beforeEach(() => { document.body.innerHTML = `<textarea id='test-textarea'></textarea>`; }); @@ -143,11 +146,11 @@ describe("InputHint", () => { const hint = new InputHint(textarea, "abc"); hint.activate(); - expect(document.activeElement).to.equal(textarea); + expect(document.activeElement).toEqual(textarea); }); }); - context("<button>", () => { + describe("<button>", () => { beforeEach(() => { document.body.innerHTML = `<button id='test-button'></button>`; }); diff --git a/test/content/presenters/NavigationPresenter.test.ts b/test/content/presenters/NavigationPresenter.test.ts index 8d003c4..0e51242 100644 --- a/test/content/presenters/NavigationPresenter.test.ts +++ b/test/content/presenters/NavigationPresenter.test.ts @@ -1,9 +1,10 @@ -import { NavigationPresenterImpl } from "../../../src/content/presenters/NavigationPresenter"; -import { expect } from "chai"; +/** + * @jest-environment jsdom + */ -describe("NavigationPresenterImpl", function () { - this.timeout(5000); +import { NavigationPresenterImpl } from "../../../src/content/presenters/NavigationPresenter"; +describe("NavigationPresenterImpl", () => { let sut: NavigationPresenterImpl; const testRel = (done: () => void, rel: string, html: string) => { @@ -12,7 +13,7 @@ describe("NavigationPresenterImpl", function () { document.body.innerHTML = html; method(); setTimeout(() => { - expect(document.location.hash).to.equal(`#${rel}`); + expect(document.location.hash).toEqual(`#${rel}`); done(); }, 0); }; @@ -21,7 +22,7 @@ describe("NavigationPresenterImpl", function () { const testNext = (html: string) => (done: () => void) => testRel(done, "next", html); - before(() => { + beforeEach(() => { sut = new NavigationPresenterImpl(); }); diff --git a/test/content/repositories/AddonEnabledRepository.test.ts b/test/content/repositories/AddonEnabledRepository.test.ts index 13dff76..692407c 100644 --- a/test/content/repositories/AddonEnabledRepository.test.ts +++ b/test/content/repositories/AddonEnabledRepository.test.ts @@ -1,14 +1,13 @@ import { AddonEnabledRepositoryImpl } from "../../../src/content/repositories/AddonEnabledRepository"; -import { expect } from "chai"; describe("AddonEnabledRepositoryImpl", () => { it("updates and gets current value", () => { const sut = new AddonEnabledRepositoryImpl(); sut.set(true); - expect(sut.get()).to.be.true; + expect(sut.get()).toBeTruthy; sut.set(false); - expect(sut.get()).to.be.false; + expect(sut.get()).toBeFalsy; }); }); diff --git a/test/content/repositories/FollowKeyRepository.test.ts b/test/content/repositories/FollowKeyRepository.test.ts index 6608662..fa35a54 100644 --- a/test/content/repositories/FollowKeyRepository.test.ts +++ b/test/content/repositories/FollowKeyRepository.test.ts @@ -1,29 +1,28 @@ import FollowKeyRepository, { FollowKeyRepositoryImpl, } from "../../../src/content/repositories/FollowKeyRepository"; -import { expect } from "chai"; describe("FollowKeyRepositoryImpl", () => { let sut: FollowKeyRepository; - before(() => { + beforeEach(() => { sut = new FollowKeyRepositoryImpl(); }); describe("#getKeys()/#pushKey()/#popKey()", () => { it("enqueues keys", () => { - expect(sut.getKeys()).to.be.empty; + expect(sut.getKeys()).toHaveLength(0); sut.pushKey("a"); sut.pushKey("b"); sut.pushKey("c"); - expect(sut.getKeys()).to.deep.equal(["a", "b", "c"]); + expect(sut.getKeys()).toEqual(["a", "b", "c"]); sut.popKey(); - expect(sut.getKeys()).to.deep.equal(["a", "b"]); + expect(sut.getKeys()).toEqual(["a", "b"]); sut.clearKeys(); - expect(sut.getKeys()).to.be.empty; + expect(sut.getKeys()).toHaveLength(0); }); }); }); diff --git a/test/content/repositories/FollowMasterRepository.test.ts b/test/content/repositories/FollowMasterRepository.test.ts index 9b5e151..6a7d0ac 100644 --- a/test/content/repositories/FollowMasterRepository.test.ts +++ b/test/content/repositories/FollowMasterRepository.test.ts @@ -1,26 +1,25 @@ import FollowMasterRepository, { FollowMasterRepositoryImpl, } from "../../../src/content/repositories/FollowMasterRepository"; -import { expect } from "chai"; describe("FollowMasterRepositoryImpl", () => { let sut: FollowMasterRepository; - before(() => { + beforeEach(() => { sut = new FollowMasterRepositoryImpl(); }); describe("#getTags()/#addTag()/#clearTags()", () => { it("gets, adds and clears tags", () => { - expect(sut.getTags()).to.be.empty; + expect(sut.getTags()).toHaveLength(0); sut.addTag("a"); sut.addTag("b"); sut.addTag("c"); - expect(sut.getTags()).to.deep.equal(["a", "b", "c"]); + expect(sut.getTags()).toEqual(["a", "b", "c"]); sut.clearTags(); - expect(sut.getTags()).to.be.empty; + expect(sut.getTags()).toHaveLength(0); }); }); @@ -29,22 +28,22 @@ describe("FollowMasterRepositoryImpl", () => { for (const tag of ["a", "aa", "ab", "b", "ba", "bb"]) { sut.addTag(tag); } - expect(sut.getTagsByPrefix("a")).to.deep.equal(["a", "aa", "ab"]); - expect(sut.getTagsByPrefix("aa")).to.deep.equal(["aa"]); - expect(sut.getTagsByPrefix("b")).to.deep.equal(["b", "ba", "bb"]); - expect(sut.getTagsByPrefix("c")).to.be.empty; + expect(sut.getTagsByPrefix("a")).toEqual(["a", "aa", "ab"]); + expect(sut.getTagsByPrefix("aa")).toEqual(["aa"]); + expect(sut.getTagsByPrefix("b")).toEqual(["b", "ba", "bb"]); + expect(sut.getTagsByPrefix("c")).toHaveLength(0); }); }); describe("#setCurrentFollowMode()/#getCurrentNewTabMode()/#getCurrentBackgroundMode", () => { it("updates and gets follow mode", () => { sut.setCurrentFollowMode(false, true); - expect(sut.getCurrentNewTabMode()).to.be.false; - expect(sut.getCurrentBackgroundMode()).to.be.true; + expect(sut.getCurrentNewTabMode()).toBeFalsy; + expect(sut.getCurrentBackgroundMode()).toBeTruthy; sut.setCurrentFollowMode(true, false); - expect(sut.getCurrentNewTabMode()).to.be.true; - expect(sut.getCurrentBackgroundMode()).to.be.false; + expect(sut.getCurrentNewTabMode()).toBeTruthy; + expect(sut.getCurrentBackgroundMode()).toBeFalsy; }); }); }); diff --git a/test/content/repositories/FollowSlaveRepository.test.ts b/test/content/repositories/FollowSlaveRepository.test.ts index 0f829b2..52ed3fc 100644 --- a/test/content/repositories/FollowSlaveRepository.test.ts +++ b/test/content/repositories/FollowSlaveRepository.test.ts @@ -1,24 +1,23 @@ import FollowSlaveRepository, { FollowSlaveRepositoryImpl, } from "../../../src/content/repositories/FollowSlaveRepository"; -import { expect } from "chai"; describe("FollowSlaveRepository", () => { let sut: FollowSlaveRepository; - before(() => { + beforeEach(() => { sut = new FollowSlaveRepositoryImpl(); }); describe("#isFollowMode()/#enableFollowMode()/#disableFollowMode()", () => { it("gets, adds updates follow mode", () => { - expect(sut.isFollowMode()).to.be.false; + expect(sut.isFollowMode()).toBeFalsy; sut.enableFollowMode(); - expect(sut.isFollowMode()).to.be.true; + expect(sut.isFollowMode()).toBeTruthy; sut.disableFollowMode(); - expect(sut.isFollowMode()).to.be.false; + expect(sut.isFollowMode()).toBeFalsy; }); }); }); diff --git a/test/content/repositories/KeymapRepository.test.ts b/test/content/repositories/KeymapRepository.test.ts index 0e01a73..715187b 100644 --- a/test/content/repositories/KeymapRepository.test.ts +++ b/test/content/repositories/KeymapRepository.test.ts @@ -1,13 +1,12 @@ import KeymapRepository, { KeymapRepositoryImpl, } from "../../../src/content/repositories/KeymapRepository"; -import { expect } from "chai"; import Key from "../../../src/shared/settings/Key"; describe("KeymapRepositoryImpl", () => { let sut: KeymapRepository; - before(() => { + beforeEach(() => { sut = new KeymapRepositoryImpl(); }); @@ -18,9 +17,9 @@ describe("KeymapRepositoryImpl", () => { const sequence = sut.enqueueKey(Key.fromMapKey("c")); const keys = sequence.keys; - expect(keys[0].equals(Key.fromMapKey("a"))).to.be.true; - expect(keys[1].equals(Key.fromMapKey("b"))).to.be.true; - expect(keys[2].equals(Key.fromMapKey("c"))).to.be.true; + expect(keys[0].equals(Key.fromMapKey("a"))).toBeTruthy; + expect(keys[1].equals(Key.fromMapKey("b"))).toBeTruthy; + expect(keys[2].equals(Key.fromMapKey("c"))).toBeTruthy; }); }); @@ -32,7 +31,7 @@ describe("KeymapRepositoryImpl", () => { sut.clear(); const sequence = sut.enqueueKey(Key.fromMapKey("a")); - expect(sequence.length()).to.equal(1); + expect(sequence.length()).toEqual(1); }); }); }); diff --git a/test/content/repositories/MarkKeyRepository.test.ts b/test/content/repositories/MarkKeyRepository.test.ts index 473b4dc..a722a9c 100644 --- a/test/content/repositories/MarkKeyRepository.test.ts +++ b/test/content/repositories/MarkKeyRepository.test.ts @@ -1,36 +1,35 @@ import MarkRepository, { MarkKeyRepositoryImpl, } from "../../../src/content/repositories/MarkKeyRepository"; -import { expect } from "chai"; describe("MarkKeyRepositoryImpl", () => { let sut: MarkRepository; - before(() => { + beforeEach(() => { sut = new MarkKeyRepositoryImpl(); }); describe("#isSetMode/#enableSetMode/#disabeSetMode", () => { it("enables and disables set mode", () => { - expect(sut.isSetMode()).to.be.false; + expect(sut.isSetMode()).toBeFalsy; sut.enableSetMode(); - expect(sut.isSetMode()).to.be.true; + expect(sut.isSetMode()).toBeTruthy; sut.disabeSetMode(); - expect(sut.isSetMode()).to.be.false; + expect(sut.isSetMode()).toBeFalsy; }); }); describe("#isJumpMode/#enableJumpMode/#disabeJumpMode", () => { it("enables and disables jump mode", () => { - expect(sut.isJumpMode()).to.be.false; + expect(sut.isJumpMode()).toBeFalsy; sut.enableJumpMode(); - expect(sut.isJumpMode()).to.be.true; + expect(sut.isJumpMode()).toBeTruthy; sut.disabeJumpMode(); - expect(sut.isJumpMode()).to.be.false; + expect(sut.isJumpMode()).toBeFalsy; }); }); }); diff --git a/test/content/repositories/MarkRepository.test.ts b/test/content/repositories/MarkRepository.test.ts index f2a7326..b4486a1 100644 --- a/test/content/repositories/MarkRepository.test.ts +++ b/test/content/repositories/MarkRepository.test.ts @@ -1,12 +1,11 @@ import { MarkRepositoryImpl } from "../../../src/content/repositories/MarkRepository"; -import { expect } from "chai"; describe("MarkRepositoryImpl", () => { it("save and load marks", () => { const sut = new MarkRepositoryImpl(); sut.set("a", { x: 10, y: 20 }); - expect(sut.get("a")).to.deep.equal({ x: 10, y: 20 }); - expect(sut.get("b")).to.be.null; + expect(sut.get("a")).toEqual({ x: 10, y: 20 }); + expect(sut.get("b")).toBeNull; }); }); diff --git a/test/content/repositories/SettingRepository.test.ts b/test/content/repositories/SettingRepository.test.ts index 99247a9..409012a 100644 --- a/test/content/repositories/SettingRepository.test.ts +++ b/test/content/repositories/SettingRepository.test.ts @@ -1,5 +1,4 @@ import { SettingRepositoryImpl } from "../../../src/content/repositories/SettingRepository"; -import { expect } from "chai"; import Settings from "../../../src/shared/settings/Settings"; describe("SettingRepositoryImpl", () => { @@ -25,6 +24,6 @@ describe("SettingRepositoryImpl", () => { sut.set(settings); const actual = sut.get(); - expect(actual.properties.hintchars).to.equal("abcd1234"); + expect(actual.properties.hintchars).toEqual("abcd1234"); }); }); diff --git a/test/content/usecases/AddonEnabledUseCase.test.ts b/test/content/usecases/AddonEnabledUseCase.test.ts index 8a614c5..3d4d667 100644 --- a/test/content/usecases/AddonEnabledUseCase.test.ts +++ b/test/content/usecases/AddonEnabledUseCase.test.ts @@ -1,7 +1,6 @@ import AddonEnabledRepository from "../../../src/content/repositories/AddonEnabledRepository"; import AddonEnabledUseCase from "../../../src/content/usecases/AddonEnabledUseCase"; import AddonIndicatorClient from "../../../src/content/client/AddonIndicatorClient"; -import { expect } from "chai"; import MockConsoleFramePresenter from "../operators/impls/MockConsoleFramePresenter"; class MockAddonEnabledRepository implements AddonEnabledRepository { @@ -50,19 +49,19 @@ describe("AddonEnabledUseCase", () => { it("store and indicate as enabled", async () => { await sut.enable(); - expect(repository.get()).to.be.true; - expect(indicator.enabled).to.be.true; - expect(presenter.attached).to.be.true; + expect(repository.get()).toBeTruthy; + expect(indicator.enabled).toBeTruthy; + expect(presenter.attached).toBeTruthy; }); }); - describe("#disable", async () => { + describe("#disable", () => { it("store and indicate as disabled", async () => { await sut.disable(); - expect(repository.get()).to.be.false; - expect(indicator.enabled).to.be.false; - expect(presenter.attached).to.be.false; + expect(repository.get()).toBeFalsy; + expect(indicator.enabled).toBeFalsy; + expect(presenter.attached).toBeFalsy; }); }); @@ -71,27 +70,27 @@ describe("AddonEnabledUseCase", () => { repository.set(true); await sut.toggle(); - expect(repository.get()).to.be.false; - expect(indicator.enabled).to.be.false; - expect(presenter.attached).to.be.false; + expect(repository.get()).toBeFalsy; + expect(indicator.enabled).toBeFalsy; + expect(presenter.attached).toBeFalsy; repository.set(false); await sut.toggle(); - expect(repository.get()).to.be.true; - expect(indicator.enabled).to.be.true; - expect(presenter.attached).to.be.true; + expect(repository.get()).toBeTruthy; + expect(indicator.enabled).toBeTruthy; + expect(presenter.attached).toBeTruthy; }); }); describe("#getEnabled", () => { it("returns current addon enabled", () => { repository.set(true); - expect(sut.getEnabled()).to.be.true; + expect(sut.getEnabled()).toBeTruthy; repository.set(false); - expect(sut.getEnabled()).to.be.false; + expect(sut.getEnabled()).toBeFalsy; }); }); }); diff --git a/test/content/usecases/HintKeyProducer.test.ts b/test/content/usecases/HintKeyProducer.test.ts index 9d320b4..a4ad4de 100644 --- a/test/content/usecases/HintKeyProducer.test.ts +++ b/test/content/usecases/HintKeyProducer.test.ts @@ -1,5 +1,4 @@ import { HintKeyRepositoryImpl } from "../../../src/content/repositories/HintKeyRepository"; -import { expect } from "chai"; describe("HintKeyProducerImpl class", () => { describe("#produce", () => { @@ -27,7 +26,7 @@ describe("HintKeyProducerImpl class", () => { const sut = new HintKeyRepositoryImpl(); sut.reset(charset); for (let i = 0; i < sequences.length; ++i) { - expect(sut.produce()).to.equal(sequences[i]); + expect(sut.produce()).toEqual(sequences[i]); } }); }); @@ -37,16 +36,16 @@ describe("HintKeyProducerImpl class", () => { const sut = new HintKeyRepositoryImpl(); sut.reset("ab"); - expect(sut.produce()).to.equal("a"); - expect(sut.produce()).to.equal("b"); + expect(sut.produce()).toEqual("a"); + expect(sut.produce()).toEqual("b"); sut.reset("xy"); - expect(sut.produce()).to.equal("x"); - expect(sut.produce()).to.equal("y"); + expect(sut.produce()).toEqual("x"); + expect(sut.produce()).toEqual("y"); }); it("throws an exception on empty charset", () => { const sut = new HintKeyRepositoryImpl(); - expect(() => sut.reset("")).to.throw(TypeError); + expect(() => sut.reset("")).toThrow(TypeError); }); }); }); diff --git a/test/content/usecases/KeymapUseCase.test.ts b/test/content/usecases/KeymapUseCase.test.ts index 24ac6d8..7af3ab2 100644 --- a/test/content/usecases/KeymapUseCase.test.ts +++ b/test/content/usecases/KeymapUseCase.test.ts @@ -1,6 +1,5 @@ import "reflect-metadata"; import KeymapUseCase from "../../../src/content/usecases/KeymapUseCase"; -import { expect } from "chai"; import SettingRepository from "../../../src/content/repositories/SettingRepository"; import Settings from "../../../src/shared/settings/Settings"; import AddonEnabledRepository from "../../../src/content/repositories/AddonEnabledRepository"; @@ -41,7 +40,7 @@ class MockAddressRepository implements AddressRepository { } describe("KeymapUseCase", () => { - context("with no-digis keymaps", () => { + describe("with no-digis keymaps", () => { const settings = Settings.fromJSON({ keymaps: { k: { type: "scroll.vertically", count: -1 }, @@ -52,7 +51,7 @@ describe("KeymapUseCase", () => { let sut: KeymapUseCase; - before(() => { + beforeEach(() => { sut = new KeymapUseCase( new KeymapRepositoryImpl(), new MockSettingRepository(settings), @@ -62,34 +61,34 @@ describe("KeymapUseCase", () => { }); it("returns matched operation", () => { - expect(sut.nextOps(Key.fromMapKey("k"))).to.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("k"))).toEqual({ repeat: 1, op: { type: "scroll.vertically", count: -1 }, }); - expect(sut.nextOps(Key.fromMapKey("j"))).to.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("j"))).toEqual({ repeat: 1, op: { type: "scroll.vertically", count: 1 }, }); - expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("g"))).toEqual({ repeat: 1, op: { type: "scroll.top" }, }); - expect(sut.nextOps(Key.fromMapKey("z"))).to.be.null; + expect(sut.nextOps(Key.fromMapKey("z"))).toBeNull; }); it("repeats n-times by numeric prefix and multiple key operations", () => { - expect(sut.nextOps(Key.fromMapKey("1"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("0"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("1"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("0"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("g"))).toEqual({ repeat: 10, op: { type: "scroll.top" }, }); }); }); - context("when keymaps containing numeric mappings", () => { + describe("when keymaps containing numeric mappings", () => { const settings = Settings.fromJSON({ keymaps: { 20: { type: "scroll.top" }, @@ -99,7 +98,7 @@ describe("KeymapUseCase", () => { let sut: KeymapUseCase; - before(() => { + beforeEach(() => { sut = new KeymapUseCase( new KeymapRepositoryImpl(), new MockSettingRepository(settings), @@ -109,43 +108,43 @@ describe("KeymapUseCase", () => { }); it("returns the matched operation ends with digit", () => { - expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("5"))).to.be.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("5"))).toEqual({ repeat: 1, op: { type: "scroll.bottom" }, }); }); it("returns an operation matched the operation with digit keymaps", () => { - expect(sut.nextOps(Key.fromMapKey("2"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("0"))).to.be.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("2"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("0"))).toEqual({ repeat: 1, op: { type: "scroll.top" }, }); }); it("returns operations repeated by numeric prefix", () => { - expect(sut.nextOps(Key.fromMapKey("2"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("5"))).to.be.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("2"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("5"))).toEqual({ repeat: 2, op: { type: "scroll.bottom" }, }); }); it("does not matches with digit operation with numeric prefix", () => { - expect(sut.nextOps(Key.fromMapKey("3"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("2"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("0"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("5"))).to.be.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("3"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("2"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("0"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("5"))).toEqual({ repeat: 320, op: { type: "scroll.bottom" }, }); }); }); - context("when the keys are mismatched with the operations", () => { + describe("when the keys are mismatched with the operations", () => { const settings = Settings.fromJSON({ keymaps: { gg: { type: "scroll.top" }, @@ -155,7 +154,7 @@ describe("KeymapUseCase", () => { let sut: KeymapUseCase; - before(() => { + beforeEach(() => { sut = new KeymapUseCase( new KeymapRepositoryImpl(), new MockSettingRepository(settings), @@ -165,31 +164,31 @@ describe("KeymapUseCase", () => { }); it("clears input keys with no-matched operations", () => { - expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("x"))).to.be.null; // clear - expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("x"))).toBeNull; // clear + expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("g"))).toEqual({ repeat: 1, op: { type: "scroll.top" }, }); }); it("clears input keys and the prefix with no-matched operations", () => { - expect(sut.nextOps(Key.fromMapKey("1"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("0"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("x"))).to.be.null; // clear - expect(sut.nextOps(Key.fromMapKey("1"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("0"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("1"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("0"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("x"))).toBeNull; // clear + expect(sut.nextOps(Key.fromMapKey("1"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("0"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("g"))).toEqual({ repeat: 10, op: { type: "scroll.top" }, }); }); }); - context("when the site matches to the blacklist", () => { + describe("when the site matches to the blacklist", () => { const settings = Settings.fromJSON({ keymaps: { k: { type: "scroll.vertically", count: -1 }, @@ -200,7 +199,7 @@ describe("KeymapUseCase", () => { let sut: KeymapUseCase; - before(() => { + beforeEach(() => { sut = new KeymapUseCase( new KeymapRepositoryImpl(), new MockSettingRepository(settings), @@ -210,19 +209,19 @@ describe("KeymapUseCase", () => { }); it("returns only ADDON_ENABLE and ADDON_TOGGLE_ENABLED operation", () => { - expect(sut.nextOps(Key.fromMapKey("k"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("a"))).to.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("k"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("a"))).toEqual({ repeat: 1, op: { type: "addon.enable" }, }); - expect(sut.nextOps(Key.fromMapKey("b"))).to.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("b"))).toEqual({ repeat: 1, op: { type: "addon.toggle.enabled" }, }); }); }); - context("when the site matches to the partial blacklist", () => { + describe("when the site matches to the partial blacklist", () => { const settings = Settings.fromJSON({ keymaps: { k: { type: "scroll.vertically", count: -1 }, @@ -244,17 +243,17 @@ describe("KeymapUseCase", () => { new MockAddressRepository(new URL("https://example.com")) ); - expect(sut.nextOps(Key.fromMapKey("k"))).to.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("k"))).toEqual({ repeat: 1, op: { type: "scroll.vertically", count: -1 }, }); - expect(sut.nextOps(Key.fromMapKey("j"))).to.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("j"))).toEqual({ repeat: 1, op: { type: "scroll.vertically", count: 1 }, }); - expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("G"))).to.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("G"))).toEqual({ repeat: 1, op: { type: "scroll.bottom" }, }); @@ -266,12 +265,12 @@ describe("KeymapUseCase", () => { new MockAddressRepository(new URL("https://example.org")) ); - expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null; - expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({ + expect(sut.nextOps(Key.fromMapKey("g"))).toBeNull; + expect(sut.nextOps(Key.fromMapKey("g"))).toEqual({ repeat: 1, op: { type: "scroll.top" }, }); - expect(sut.nextOps(Key.fromMapKey("G"))).to.be.null; + expect(sut.nextOps(Key.fromMapKey("G"))).toBeNull; }); }); }); diff --git a/test/content/usecases/MarkUseCase.test.ts b/test/content/usecases/MarkUseCase.test.ts index df3f7bf..b788c3c 100644 --- a/test/content/usecases/MarkUseCase.test.ts +++ b/test/content/usecases/MarkUseCase.test.ts @@ -5,7 +5,6 @@ import MarkClient from "../../../src/content/client/MarkClient"; import MockConsoleClient from "../mock/MockConsoleClient"; import MockScrollPresenter from "../mock/MockScrollPresenter"; import Mark from "../../../src/content/domains/Mark"; -import { expect } from "chai"; class MockMarkRepository implements MarkRepository { private current: { [key: string]: Mark }; @@ -70,8 +69,8 @@ describe("MarkUseCase", () => { await sut.set("x"); - expect(repository.get("x")).to.deep.equals({ x: 10, y: 20 }); - expect(consoleClient.text).to.equal("Set local mark to 'x'"); + expect(repository.get("x")).toEqual({ x: 10, y: 20 }); + expect(consoleClient.text).toEqual("Set local mark to 'x'"); }); it("sets global mark", async () => { @@ -79,8 +78,8 @@ describe("MarkUseCase", () => { await sut.set("Z"); - expect(client.marks["Z"]).to.deep.equals({ x: 30, y: 40 }); - expect(consoleClient.text).to.equal("Set global mark to 'Z'"); + expect(client.marks["Z"]).toEqual({ x: 30, y: 40 }); + expect(consoleClient.text).toEqual("Set global mark to 'Z'"); }); }); @@ -90,7 +89,7 @@ describe("MarkUseCase", () => { await sut.jump("x"); - expect(scrollPresenter.getScroll()).to.deep.equals({ x: 20, y: 40 }); + expect(scrollPresenter.getScroll()).toEqual({ x: 20, y: 40 }); }); it("throws an error when no local marks", () => { @@ -100,7 +99,7 @@ describe("MarkUseCase", () => { throw new Error("error"); }) .catch((e) => { - expect(e).to.be.instanceof(Error); + expect(e).toBeInstanceOf(Error); }); }); @@ -109,7 +108,7 @@ describe("MarkUseCase", () => { await sut.jump("Z"); - expect(client.last).to.equal("Z"); + expect(client.last).toEqual("Z"); }); }); }); diff --git a/test/content/usecases/SettingUseCaase.test.ts b/test/content/usecases/SettingUseCaase.test.ts index 1cc1e8a..8339bd9 100644 --- a/test/content/usecases/SettingUseCaase.test.ts +++ b/test/content/usecases/SettingUseCaase.test.ts @@ -4,7 +4,6 @@ import SettingUseCase from "../../../src/content/usecases/SettingUseCase"; import Settings, { DefaultSetting, } from "../../../src/shared/settings/Settings"; -import { expect } from "chai"; class MockSettingRepository implements SettingRepository { private current: Settings; @@ -64,10 +63,10 @@ describe("AddonEnabledUseCase", () => { describe("#reload", () => { it("loads settings and store to repository", async () => { const settings = await sut.reload(); - expect(settings.properties.hintchars).to.equal("abcd1234"); + expect(settings.properties.hintchars).toEqual("abcd1234"); const saved = repository.get(); - expect(saved.properties.hintchars).to.equal("abcd1234"); + expect(saved.properties.hintchars).toEqual("abcd1234"); }); }); }); diff --git a/test/settings/components/form/BlacklistForm.test.tsx b/test/settings/components/form/BlacklistForm.test.tsx index 8727c59..bd1a1e8 100644 --- a/test/settings/components/form/BlacklistForm.test.tsx +++ b/test/settings/components/form/BlacklistForm.test.tsx @@ -1,8 +1,11 @@ +/** + * @jest-environment jsdom + */ + import React from "react"; import ReactDOM from "react-dom"; import ReactTestRenderer from "react-test-renderer"; import ReactTestUtils from "react-dom/test-utils"; -import { expect } from "chai"; import BlacklistForm from "../../../../src/settings/components/form/BlacklistForm"; import Blacklist from "../../../../src/shared/settings/Blacklist"; @@ -20,15 +23,15 @@ describe("settings/form/BlacklistForm", () => { const rows = root .findAllByType("div") .filter((instance) => instance.props.role === "listitem"); - expect(rows).to.have.lengthOf(2); - expect(rows[0].findByProps({ name: "url" }).props.value).to.equal( + expect(rows).toHaveLength(2); + expect(rows[0].findByProps({ name: "url" }).props.value).toEqual( "*.slack.com" ); - expect(rows[1].findByProps({ name: "url" }).props.value).to.equal( + expect(rows[1].findByProps({ name: "url" }).props.value).toEqual( "www.google.com/maps" ); - expect(() => root.findByType(AddButton)).not.throw(); + expect(() => root.findByType(AddButton)).not.toThrow(); }); it("renders blank value", () => { @@ -37,7 +40,7 @@ describe("settings/form/BlacklistForm", () => { const rows = root.findAllByProps({ className: "form-blacklist-form-row", }); - expect(rows).to.be.empty; + expect(rows).toHaveLength(0); }); }); @@ -60,10 +63,7 @@ describe("settings/form/BlacklistForm", () => { value={Blacklist.fromJSON(["*.slack.com", "www.google.com/maps*"])} onChange={(value) => { const urls = value.items.map((item) => item.pattern); - expect(urls).to.have.members([ - "gitter.im", - "www.google.com/maps*", - ]); + expect(urls).toEqual(["gitter.im", "www.google.com/maps*"]); done(); }} />, @@ -85,7 +85,7 @@ describe("settings/form/BlacklistForm", () => { value={Blacklist.fromJSON(["*.slack.com", "www.google.com/maps*"])} onChange={(value) => { const urls = value.items.map((item) => item.pattern); - expect(urls).to.have.members(["www.google.com/maps*"]); + expect(urls).toEqual(["www.google.com/maps*"]); done(); }} />, @@ -104,7 +104,7 @@ describe("settings/form/BlacklistForm", () => { value={Blacklist.fromJSON(["*.slack.com"])} onChange={(value) => { const urls = value.items.map((item) => item.pattern); - expect(urls).to.have.members(["*.slack.com", ""]); + expect(urls).toEqual(["*.slack.com", ""]); done(); }} />, diff --git a/test/settings/components/form/KeymapsForm.test.tsx b/test/settings/components/form/KeymapsForm.test.tsx index 1cec889..4701a96 100644 --- a/test/settings/components/form/KeymapsForm.test.tsx +++ b/test/settings/components/form/KeymapsForm.test.tsx @@ -1,10 +1,13 @@ +/** + * @jest-environment jsdom + */ + import React from "react"; import ReactDOM from "react-dom"; import ReactTestRenderer from "react-test-renderer"; import ReactTestUtils from "react-dom/test-utils"; import KeymapsForm from "../../../../src/settings/components/form/KeymapsForm"; import { FormKeymaps } from "../../../../src/shared/SettingData"; -import { expect } from "chai"; describe("settings/form/KeymapsForm", () => { describe("render", () => { @@ -21,8 +24,8 @@ describe("settings/form/KeymapsForm", () => { const inputj = root.findByProps({ id: 'scroll.vertically?{"count":1}' }); const inputk = root.findByProps({ id: 'scroll.vertically?{"count":-1}' }); - expect(inputj.props.value).to.equal("j"); - expect(inputk.props.value).to.equal("k"); + expect(inputj.props.value).toEqual("j"); + expect(inputk.props.value).toEqual("k"); }); it("renders blank value", () => { @@ -31,8 +34,8 @@ describe("settings/form/KeymapsForm", () => { const inputj = root.findByProps({ id: 'scroll.vertically?{"count":1}' }); const inputk = root.findByProps({ id: 'scroll.vertically?{"count":-1}' }); - expect(inputj.props.value).to.be.empty; - expect(inputk.props.value).to.be.empty; + expect(inputj.props.value).toHaveLength(0); + expect(inputk.props.value).toHaveLength(0); }); }); @@ -57,7 +60,7 @@ describe("settings/form/KeymapsForm", () => { 'scroll.vertically?{"count":-1}': "k", })} onChange={(value) => { - expect(value.toJSON()['scroll.vertically?{"count":1}']).to.equal( + expect(value.toJSON()['scroll.vertically?{"count":1}']).toEqual( "jjj" ); done(); diff --git a/test/settings/components/form/PropertiesForm.test.tsx b/test/settings/components/form/PropertiesForm.test.tsx index acf02b8..0b481ab 100644 --- a/test/settings/components/form/PropertiesForm.test.tsx +++ b/test/settings/components/form/PropertiesForm.test.tsx @@ -1,9 +1,12 @@ +/** + * @jest-environment jsdom + */ + import React from "react"; import ReactDOM from "react-dom"; import ReactTestRenderer from "react-test-renderer"; import ReactTestUtils from "react-dom/test-utils"; import PropertiesForm from "../../../../src/settings/components/form/PropertiesForm"; -import { expect } from "chai"; describe("settings/form/PropertiesForm", () => { describe("render", () => { @@ -25,16 +28,16 @@ describe("settings/form/PropertiesForm", () => { ).root; let input = root.findByProps({ name: "mystr" }); - expect(input.props.type).to.equals("text"); - expect(input.props.value).to.equal("abc"); + expect(input.props.type).toEqual("text"); + expect(input.props.value).toEqual("abc"); input = root.findByProps({ name: "mynum" }); - expect(input.props.type).to.equals("number"); - expect(input.props.value).to.equal(123); + expect(input.props.type).toEqual("number"); + expect(input.props.value).toEqual(123); input = root.findByProps({ name: "mybool" }); - expect(input.props.type).to.equals("checkbox"); - expect(input.props.value).to.equal(true); + expect(input.props.type).toEqual("checkbox"); + expect(input.props.value).toEqual(true); }); }); @@ -57,7 +60,7 @@ describe("settings/form/PropertiesForm", () => { types={{ myvalue: "string" }} value={{ myvalue: "abc" }} onChange={(value) => { - expect(value).to.have.property("myvalue", "abcd"); + expect(value).toHaveProperty("myvalue", "abcd"); done(); }} />, @@ -79,7 +82,7 @@ describe("settings/form/PropertiesForm", () => { types={{ myvalue: "number" }} value={{ "": 123 }} onChange={(value) => { - expect(value).to.have.property("myvalue", 1234); + expect(value).toHaveProperty("myvalue", 1234); done(); }} />, @@ -101,7 +104,7 @@ describe("settings/form/PropertiesForm", () => { types={{ myvalue: "boolean" }} value={{ myvalue: false }} onChange={(value) => { - expect(value).to.have.property("myvalue", true); + expect(value).toHaveProperty("myvalue", true); done(); }} />, diff --git a/test/settings/components/form/SearchEngineForm.test.tsx b/test/settings/components/form/SearchEngineForm.test.tsx index 7b10274..8b84e12 100644 --- a/test/settings/components/form/SearchEngineForm.test.tsx +++ b/test/settings/components/form/SearchEngineForm.test.tsx @@ -1,10 +1,13 @@ +/** + * @jest-environment jsdom + */ + import React from "react"; import ReactDOM from "react-dom"; import ReactTestRenderer from "react-test-renderer"; import ReactTestUtils from "react-dom/test-utils"; import SearchForm from "../../../../src/settings/components/form/SearchForm"; import { FormSearch } from "../../../../src/shared/SettingData"; -import { expect } from "chai"; describe("settings/form/SearchForm", () => { describe("render", () => { @@ -24,16 +27,16 @@ describe("settings/form/SearchForm", () => { const names = root .findAllByType("input") .filter((instance) => instance.props.name === "name"); - expect(names).to.have.lengthOf(2); - expect(names[0].props.value).to.equal("google"); - expect(names[1].props.value).to.equal("yahoo"); + expect(names).toHaveLength(2); + expect(names[0].props.value).toEqual("google"); + expect(names[1].props.value).toEqual("yahoo"); const urls = root .findAllByType("input") .filter((instance) => instance.props.name === "url"); - expect(urls).to.have.lengthOf(2); - expect(urls[0].props.value).to.equal("google.com"); - expect(urls[1].props.value).to.equal("yahoo.com"); + expect(urls).toHaveLength(2); + expect(urls[0].props.value).toEqual("google.com"); + expect(urls[1].props.value).toEqual("yahoo.com"); }); }); @@ -62,9 +65,9 @@ describe("settings/form/SearchForm", () => { })} onChange={(value) => { const json = value.toJSON(); - expect(json.default).to.equal("louvre"); - expect(json.engines).to.have.lengthOf(2); - expect(json.engines).to.have.deep.members([ + expect(json.default).toEqual("louvre"); + expect(json.engines).toHaveLength(2); + expect(json.engines).toEqual([ ["louvre", "google.com"], ["yahoo", "yahoo.com"], ]); @@ -101,11 +104,9 @@ describe("settings/form/SearchForm", () => { })} onChange={(value) => { const json = value.toJSON(); - expect(json.default).to.equal("yahoo"); - expect(json.engines).to.have.lengthOf(1); - expect(json.engines).to.have.deep.members([ - ["yahoo", "yahoo.com"], - ]); + expect(json.default).toEqual("yahoo"); + expect(json.engines).toHaveLength(1); + expect(json.engines).toEqual([["yahoo", "yahoo.com"]]); done(); }} />, @@ -129,9 +130,9 @@ describe("settings/form/SearchForm", () => { })} onChange={(value) => { const json = value.toJSON(); - expect(json.default).to.equal("yahoo"); - expect(json.engines).to.have.lengthOf(2); - expect(json.engines).to.have.deep.members([ + expect(json.default).toEqual("yahoo"); + expect(json.engines).toHaveLength(2); + expect(json.engines).toEqual([ ["google", "google.com"], ["", ""], ]); diff --git a/test/settings/components/ui/Radio.test.tsx b/test/settings/components/ui/Radio.test.tsx index f929ee3..e2bf214 100644 --- a/test/settings/components/ui/Radio.test.tsx +++ b/test/settings/components/ui/Radio.test.tsx @@ -1,8 +1,11 @@ +/** + * @jest-environment jsdom + */ + import React from "react"; import ReactDOM from "react-dom"; import ReactTestUtils from "react-dom/test-utils"; import Radio from "../../../../src/settings/components/ui/Radio"; -import { expect } from "chai"; describe("settings/ui/Radio", () => { let container: HTMLDivElement; @@ -26,10 +29,10 @@ describe("settings/ui/Radio", () => { const label = document.querySelector("label")!; const input = document.querySelector("input")!; - expect(label.textContent).to.contain("myfield"); - expect(input.type).to.contain("radio"); - expect(input.name).to.contain("myradio"); - expect(input.value).to.contain("myvalue"); + expect(label.textContent).toEqual("myfield"); + expect(input.type).toEqual("radio"); + expect(input.name).toEqual("myradio"); + expect(input.value).toEqual("myvalue"); }); it("invoke onChange", (done) => { @@ -41,7 +44,7 @@ describe("settings/ui/Radio", () => { label="myfield" value="myvalue" onChange={(e) => { - expect((e.target as HTMLInputElement).checked).to.be.true; + expect((e.target as HTMLInputElement).checked).toBeTruthy; done(); }} />, diff --git a/test/settings/components/ui/Text.test.tsx b/test/settings/components/ui/Text.test.tsx index d5451bb..a8e0bf9 100644 --- a/test/settings/components/ui/Text.test.tsx +++ b/test/settings/components/ui/Text.test.tsx @@ -1,8 +1,11 @@ +/** + * @jest-environment jsdom + */ + import React from "react"; import ReactDOM from "react-dom"; import ReactTestUtils from "react-dom/test-utils"; import Text from "../../../../src/settings/components/ui/Text"; -import { expect } from "chai"; describe("settings/ui/Text", () => { let container: HTMLDivElement; @@ -26,10 +29,10 @@ describe("settings/ui/Text", () => { const label = document.querySelector("label")!; const input = document.querySelector("input")!; - expect(label.textContent).to.contain("myfield"); - expect(input.type).to.contain("text"); - expect(input.name).to.contain("myname"); - expect(input.value).to.contain("myvalue"); + expect(label.textContent?.includes("myfield")).toBeTruthy; + expect(input.type).toEqual("text"); + expect(input.name).toEqual("myname"); + expect(input.value).toEqual("myvalue"); }); it("invoke onChange", (done) => { @@ -40,7 +43,7 @@ describe("settings/ui/Text", () => { label="myfield" value="myvalue" onChange={(e) => { - expect((e.target as HTMLInputElement).value).to.equal("newvalue"); + expect((e.target as HTMLInputElement).value).toEqual("newvalue"); done(); }} />, diff --git a/test/settings/components/ui/TextArea.test.tsx b/test/settings/components/ui/TextArea.test.tsx index 232c7c0..76caec2 100644 --- a/test/settings/components/ui/TextArea.test.tsx +++ b/test/settings/components/ui/TextArea.test.tsx @@ -1,8 +1,11 @@ +/** + * @jest-environment jsdom + */ + import React from "react"; import ReactDOM from "react-dom"; import ReactTestUtils from "react-dom/test-utils"; import TextArea from "../../../../src/settings/components/ui/TextArea"; -import { expect } from "chai"; describe("settings/ui/TextArea", () => { let container: HTMLDivElement; @@ -20,7 +23,6 @@ describe("settings/ui/TextArea", () => { ReactTestUtils.act(() => { ReactDOM.render( <TextArea - type="textarea" name="myname" label="myfield" value="myvalue" @@ -33,11 +35,11 @@ describe("settings/ui/TextArea", () => { const label = document.querySelector("label")!; const textarea = document.querySelector("textarea")!; const error = document.querySelector("[role=alert]")!; - expect(label.textContent).to.contain("myfield"); - expect(textarea.nodeName).to.contain("TEXTAREA"); - expect(textarea.name).to.contain("myname"); - expect(textarea.value).to.contain("myvalue"); - expect(error.textContent).to.contain("myerror"); + expect(label.textContent).toEqual("myfield"); + expect(textarea.nodeName).toEqual("TEXTAREA"); + expect(textarea.name).toEqual("myname"); + expect(textarea.value).toEqual("myvalue"); + expect(error.textContent).toEqual("myerror"); }); it("invoke onChange", (done) => { @@ -48,7 +50,7 @@ describe("settings/ui/TextArea", () => { label="myfield" value="myvalue" onChange={(e) => { - expect((e.target as HTMLInputElement).value).to.equal("newvalue"); + expect((e.target as HTMLTextAreaElement).value).toEqual("newvalue"); done(); }} />, diff --git a/test/settings/reducers/setting.test.ts b/test/settings/reducers/setting.test.ts index 34e76e2..85b55ee 100644 --- a/test/settings/reducers/setting.test.ts +++ b/test/settings/reducers/setting.test.ts @@ -1,6 +1,5 @@ import * as actions from "../../../src/settings/actions"; import settingReducer from "../../../src/settings/reducers/setting"; -import { expect } from "chai"; import { FormSettings, JSONTextSettings, @@ -11,8 +10,8 @@ import { DefaultSetting } from "../../../src/shared/settings/Settings"; describe("settings setting reducer", () => { it("return the initial state", () => { const state = settingReducer(undefined, {} as any); - expect(state).to.have.deep.property("source", "json"); - expect(state).to.have.deep.property("error", ""); + expect(state).toHaveProperty("source", "json"); + expect(state).toHaveProperty("error", ""); }); it("return next state for SETTING_SET_SETTINGS", () => { @@ -23,9 +22,9 @@ describe("settings setting reducer", () => { form: FormSettings.fromSettings(DefaultSetting), }; const state = settingReducer(undefined, action); - expect(state.source).to.equal("json"); - expect(state.json!.toJSONText()).to.equal('{ "key": "value" }'); - expect(state.form).to.deep.equal(action.form); + expect(state.source).toEqual("json"); + expect(state.json!.toJSONText()).toEqual('{ "key": "value" }'); + expect(state.form).toEqual(action.form); }); it("return next state for SETTING_SHOW_ERROR", () => { @@ -35,8 +34,8 @@ describe("settings setting reducer", () => { json: JSONTextSettings.fromText("{}"), }; const state = settingReducer(undefined, action); - expect(state.error).to.equal("bad value"); - expect(state.json!.toJSONText()).to.equal("{}"); + expect(state.error).toEqual("bad value"); + expect(state.json!.toJSONText()).toEqual("{}"); }); it("return next state for SETTING_SWITCH_TO_FORM", () => { @@ -45,8 +44,8 @@ describe("settings setting reducer", () => { form: FormSettings.fromSettings(DefaultSetting), }; const state = settingReducer(undefined, action); - expect(state.form).to.deep.equal(action.form); - expect(state.source).to.equal("form"); + expect(state.form).toEqual(action.form); + expect(state.source).toEqual("form"); }); it("return next state for SETTING_SWITCH_TO_JSON", () => { @@ -55,7 +54,7 @@ describe("settings setting reducer", () => { json: JSONTextSettings.fromText("{}"), }; const state = settingReducer(undefined, action); - expect(state.json!.toJSONText()).to.equal("{}"); - expect(state.source).to.equal(SettingSource.JSON); + expect(state.json!.toJSONText()).toEqual("{}"); + expect(state.source).toEqual(SettingSource.JSON); }); }); diff --git a/test/shared/SettingData.test.ts b/test/shared/SettingData.test.ts index 3cfd5c9..f2c4aa9 100644 --- a/test/shared/SettingData.test.ts +++ b/test/shared/SettingData.test.ts @@ -4,7 +4,6 @@ import SettingData, { FormSettings, } from "../../src/shared/SettingData"; import Settings from "../../src/shared/settings/Settings"; -import { expect } from "chai"; import Keymaps from "../../src/shared/settings/Keymaps"; import ColorScheme from "../../src/shared/ColorScheme"; @@ -18,7 +17,7 @@ describe("shared/SettingData", () => { }; const keymaps = FormKeymaps.fromJSON(data).toKeymaps().toJSON(); - expect(keymaps).to.deep.equal({ + expect(keymaps).toEqual({ j: { type: "scroll.vertically", count: 1 }, "0": { type: "scroll.home" }, }); @@ -33,7 +32,7 @@ describe("shared/SettingData", () => { }); const form = FormKeymaps.fromKeymaps(keymaps).toJSON(); - expect(form).to.deep.equal({ + expect(form).toEqual({ 'scroll.vertically?{"count":1}': "j", "scroll.home": "0", }); @@ -62,7 +61,7 @@ describe("shared/SettingData", () => { }`; const settings = JSONTextSettings.fromText(o).toSettings(); - expect(settings.toJSON()).to.deep.equal(JSON.parse(o)); + expect(settings.toJSON()).toEqual(JSON.parse(o)); }); }); @@ -85,7 +84,7 @@ describe("shared/SettingData", () => { }); const json = JSONTextSettings.fromSettings(o).toJSONText(); - expect(JSON.parse(json)).to.deep.equal(o.toJSON()); + expect(JSON.parse(json)).toEqual(o.toJSON()); }); }); }); @@ -112,7 +111,7 @@ describe("shared/SettingData", () => { }; const settings = FormSettings.fromJSON(data).toSettings(); - expect(settings.toJSON()).to.deep.equal({ + expect(settings.toJSON()).toEqual({ keymaps: { j: { type: "scroll.vertically", count: 1 }, "0": { type: "scroll.home" }, @@ -157,7 +156,7 @@ describe("shared/SettingData", () => { }); const json = FormSettings.fromSettings(data).toJSON(); - expect(json).to.deep.equal({ + expect(json).toEqual({ keymaps: { 'scroll.vertically?{"count":1}': "j", "scroll.home": "0", @@ -202,8 +201,8 @@ describe("shared/SettingData", () => { }; const j = SettingData.fromJSON(data).toJSON(); - expect(j.source).to.equal("json"); - expect(j.json).to.be.a("string"); + expect(j.source).toEqual("json"); + expect(typeof j.json).toEqual("string"); }); it("parse object from form source", () => { @@ -226,8 +225,8 @@ describe("shared/SettingData", () => { }; const j = SettingData.fromJSON(data).toJSON(); - expect(j.source).to.equal("form"); - expect(j.form).to.deep.equal({ + expect(j.source).toEqual("form"); + expect(j.form).toEqual({ keymaps: {}, search: { default: "yahoo", @@ -266,7 +265,7 @@ describe("shared/SettingData", () => { }; const settings = SettingData.fromJSON(data).toSettings(); - expect(settings.search.defaultEngine).to.equal("google"); + expect(settings.search.defaultEngine).toEqual("google"); }); it("parse object from form source", () => { @@ -288,7 +287,7 @@ describe("shared/SettingData", () => { }; const settings = SettingData.fromJSON(data).toSettings(); - expect(settings.search.defaultEngine).to.equal("yahoo"); + expect(settings.search.defaultEngine).toEqual("yahoo"); }); }); }); diff --git a/test/shared/operations.test.ts b/test/shared/operations.test.ts index 449b25e..9fa9e19 100644 --- a/test/shared/operations.test.ts +++ b/test/shared/operations.test.ts @@ -1,5 +1,4 @@ import * as operations from "../../src/shared/operations"; -import { expect } from "chai"; describe("operations", () => { describe("#valueOf", () => { @@ -8,8 +7,8 @@ describe("operations", () => { type: operations.SCROLL_VERTICALLY, count: 10, }) as operations.ScrollVerticallyOperation; - expect(op.type).to.equal(operations.SCROLL_VERTICALLY); - expect(op.count).to.equal(10); + expect(op.type).toEqual(operations.SCROLL_VERTICALLY); + expect(op.count).toEqual(10); }); it("throws an Error on missing required parameter", () => { @@ -17,7 +16,7 @@ describe("operations", () => { operations.valueOf({ type: operations.SCROLL_VERTICALLY, }) - ).to.throw(TypeError); + ).toThrow(TypeError); }); it("fills default valus of optional parameter", () => { @@ -25,8 +24,8 @@ describe("operations", () => { type: operations.COMMAND_SHOW_OPEN, }) as operations.CommandShowOpenOperation; - expect(op.type).to.equal(operations.COMMAND_SHOW_OPEN); - expect(op.alter).to.be.false; + expect(op.type).toEqual(operations.COMMAND_SHOW_OPEN); + expect(op.alter).toBeFalsy; }); it("throws an Error on mismatch of parameter", () => { @@ -35,14 +34,14 @@ describe("operations", () => { type: operations.SCROLL_VERTICALLY, count: "10", }) - ).to.throw(TypeError); + ).toThrow(TypeError); expect(() => operations.valueOf({ type: operations.COMMAND_SHOW_OPEN, alter: "true", }) - ).to.throw(TypeError); + ).toThrow(TypeError); }); }); }); diff --git a/test/shared/settings/Blacklist.test.ts b/test/shared/settings/Blacklist.test.ts index 1ccb32a..af7b946 100644 --- a/test/shared/settings/Blacklist.test.ts +++ b/test/shared/settings/Blacklist.test.ts @@ -1,15 +1,14 @@ import Blacklist, { BlacklistItem, } from "../../../src/shared/settings/Blacklist"; -import { expect } from "chai"; import Key from "../../../src/shared/settings/Key"; describe("BlacklistItem", () => { describe("#fromJSON", () => { it("parses string pattern", () => { const item = BlacklistItem.fromJSON("example.com"); - expect(item.pattern).to.equal("example.com"); - expect(item.partial).to.be.false; + expect(item.pattern).toEqual("example.com"); + expect(item.partial).toBeFalsy; }); it("parses partial blacklist item", () => { @@ -17,56 +16,56 @@ describe("BlacklistItem", () => { url: "example.com", keys: ["j", "k"], }); - expect(item.pattern).to.equal("example.com"); - expect(item.partial).to.be.true; - expect(item.keys).to.deep.equal(["j", "k"]); + expect(item.pattern).toEqual("example.com"); + expect(item.partial).toBeTruthy; + expect(item.keys).toEqual(["j", "k"]); }); }); describe("#matches", () => { it('matches by "*"', () => { const item = BlacklistItem.fromJSON("*"); - expect(item.matches(new URL("https://github.com/abc"))).to.be.true; + expect(item.matches(new URL("https://github.com/abc"))).toBeTruthy; }); it("matches by hostname", () => { const item = BlacklistItem.fromJSON("github.com"); - expect(item.matches(new URL("https://github.com"))).to.be.true; - expect(item.matches(new URL("https://gist.github.com"))).to.be.false; - expect(item.matches(new URL("https://github.com/ueokande"))).to.be.true; - expect(item.matches(new URL("https://github.org"))).to.be.false; - expect(item.matches(new URL("https://google.com/search?q=github.org"))).to - .be.false; + expect(item.matches(new URL("https://github.com"))).toBeTruthy; + expect(item.matches(new URL("https://gist.github.com"))).toBeFalsy; + expect(item.matches(new URL("https://github.com/ueokande"))).toBeTruthy; + expect(item.matches(new URL("https://github.org"))).toBeFalsy; + expect(item.matches(new URL("https://google.com/search?q=github.org"))) + .toBeFalsy; }); it("matches by hostname with wildcard", () => { const item = BlacklistItem.fromJSON("*.github.com"); - expect(item.matches(new URL("https://github.com"))).to.be.false; - expect(item.matches(new URL("https://gist.github.com"))).to.be.true; + expect(item.matches(new URL("https://github.com"))).toBeFalsy; + expect(item.matches(new URL("https://gist.github.com"))).toBeTruthy; }); it("matches by path", () => { const item = BlacklistItem.fromJSON("github.com/abc"); - expect(item.matches(new URL("https://github.com/abc"))).to.be.true; - expect(item.matches(new URL("https://github.com/abcdef"))).to.be.false; - expect(item.matches(new URL("https://gist.github.com/abc"))).to.be.false; + expect(item.matches(new URL("https://github.com/abc"))).toBeTruthy; + expect(item.matches(new URL("https://github.com/abcdef"))).toBeFalsy; + expect(item.matches(new URL("https://gist.github.com/abc"))).toBeFalsy; }); it("matches by path with wildcard", () => { const item = BlacklistItem.fromJSON("github.com/abc*"); - expect(item.matches(new URL("https://github.com/abc"))).to.be.true; - expect(item.matches(new URL("https://github.com/abcdef"))).to.be.true; - expect(item.matches(new URL("https://gist.github.com/abc"))).to.be.false; + expect(item.matches(new URL("https://github.com/abc"))).toBeTruthy; + expect(item.matches(new URL("https://github.com/abcdef"))).toBeTruthy; + expect(item.matches(new URL("https://gist.github.com/abc"))).toBeFalsy; }); it("matches address and port", () => { const item = BlacklistItem.fromJSON("127.0.0.1:8888"); - expect(item.matches(new URL("http://127.0.0.1:8888/"))).to.be.true; - expect(item.matches(new URL("http://127.0.0.1:8888/hello"))).to.be.true; + expect(item.matches(new URL("http://127.0.0.1:8888/"))).toBeTruthy; + expect(item.matches(new URL("http://127.0.0.1:8888/hello"))).toBeTruthy; }); it("matches with partial blacklist", () => { @@ -75,8 +74,8 @@ describe("BlacklistItem", () => { keys: ["j", "k"], }); - expect(item.matches(new URL("https://google.com"))).to.be.true; - expect(item.matches(new URL("https://yahoo.com"))).to.be.false; + expect(item.matches(new URL("https://google.com"))).toBeTruthy; + expect(item.matches(new URL("https://yahoo.com"))).toBeFalsy; }); }); @@ -89,22 +88,22 @@ describe("BlacklistItem", () => { expect( item.includeKey(new URL("http://google.com/maps"), Key.fromMapKey("j")) - ).to.be.true; + ).toBeTruthy; expect( item.includeKey( new URL("http://google.com/maps"), Key.fromMapKey("<C-U>") ) - ).to.be.true; + ).toBeTruthy; expect( item.includeKey(new URL("http://google.com/maps"), Key.fromMapKey("z")) - ).to.be.false; + ).toBeFalsy; expect( item.includeKey(new URL("http://google.com/maps"), Key.fromMapKey("u")) - ).to.be.false; + ).toBeFalsy; expect( item.includeKey(new URL("http://maps.google.com/"), Key.fromMapKey("j")) - ).to.be.false; + ).toBeFalsy; }); }); }); @@ -113,7 +112,7 @@ describe("Blacklist", () => { describe("#fromJSON", () => { it("parses string list", () => { const blacklist = Blacklist.fromJSON(["example.com", "example.org"]); - expect(blacklist.toJSON()).to.deep.equals(["example.com", "example.org"]); + expect(blacklist.toJSON()).toEqual(["example.com", "example.org"]); }); it("parses mixed blacklist", () => { @@ -121,7 +120,7 @@ describe("Blacklist", () => { { url: "example.com", keys: ["j", "k"] }, "example.org", ]); - expect(blacklist.toJSON()).to.deep.equals([ + expect(blacklist.toJSON()).toEqual([ { url: "example.com", keys: ["j", "k"] }, "example.org", ]); @@ -129,7 +128,7 @@ describe("Blacklist", () => { it("parses empty blacklist", () => { const blacklist = Blacklist.fromJSON([]); - expect(blacklist.toJSON()).to.deep.equals([]); + expect(blacklist.toJSON()).toEqual([]); }); }); @@ -137,12 +136,12 @@ describe("Blacklist", () => { it("matches a url with entire blacklist", () => { const blacklist = Blacklist.fromJSON(["google.com", "*.github.com"]); expect(blacklist.includesEntireBlacklist(new URL("https://google.com"))) - .to.be.true; + .toBeTruthy; expect(blacklist.includesEntireBlacklist(new URL("https://github.com"))) - .to.be.false; + .toBeFalsy; expect( blacklist.includesEntireBlacklist(new URL("https://gist.github.com")) - ).to.be.true; + ).toBeTruthy; }); it("does not matches with partial blacklist", () => { @@ -151,9 +150,9 @@ describe("Blacklist", () => { { url: "yahoo.com", keys: ["j", "k"] }, ]); expect(blacklist.includesEntireBlacklist(new URL("https://google.com"))) - .to.be.true; - expect(blacklist.includesEntireBlacklist(new URL("https://yahoo.com"))).to - .be.false; + .toBeTruthy; + expect(blacklist.includesEntireBlacklist(new URL("https://yahoo.com"))) + .toBeFalsy; }); }); @@ -166,13 +165,13 @@ describe("Blacklist", () => { expect( blacklist.includeKey(new URL("https://google.com"), Key.fromMapKey("j")) - ).to.be.false; + ).toBeFalsy; expect( blacklist.includeKey(new URL("https://github.com"), Key.fromMapKey("j")) - ).to.be.true; + ).toBeTruthy; expect( blacklist.includeKey(new URL("https://github.com"), Key.fromMapKey("a")) - ).to.be.false; + ).toBeFalsy; }); }); }); diff --git a/test/shared/settings/Key.test.ts b/test/shared/settings/Key.test.ts index 47af1d9..8ad9265 100644 --- a/test/shared/settings/Key.test.ts +++ b/test/shared/settings/Key.test.ts @@ -1,89 +1,88 @@ -import { expect } from "chai"; import Key from "../../../src/shared/settings/Key"; describe("Key", () => { describe("fromMapKey", () => { it("return for X", () => { const key = Key.fromMapKey("x"); - expect(key.key).to.equal("x"); - expect(key.shift).to.be.false; - expect(key.ctrl).to.be.false; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("x"); + expect(key.shift).toBeFalsy; + expect(key.ctrl).toBeFalsy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); it("return for Shift+X", () => { const key = Key.fromMapKey("X"); - expect(key.key).to.equal("X"); - expect(key.shift).to.be.true; - expect(key.ctrl).to.be.false; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("X"); + expect(key.shift).toBeTruthy; + expect(key.ctrl).toBeFalsy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); it("return for Ctrl+X", () => { const key = Key.fromMapKey("<C-X>"); - expect(key.key).to.equal("x"); - expect(key.shift).to.be.false; - expect(key.ctrl).to.be.true; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("x"); + expect(key.shift).toBeFalsy; + expect(key.ctrl).toBeTruthy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); it("returns for Ctrl+Meta+X", () => { const key = Key.fromMapKey("<C-M-X>"); - expect(key.key).to.equal("x"); - expect(key.shift).to.be.false; - expect(key.ctrl).to.be.true; - expect(key.alt).to.be.false; - expect(key.meta).to.be.true; + expect(key.key).toEqual("x"); + expect(key.shift).toBeFalsy; + expect(key.ctrl).toBeTruthy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeTruthy; }); it("returns for Ctrl+Shift+x", () => { const key = Key.fromMapKey("<C-S-x>"); - expect(key.key).to.equal("X"); - expect(key.shift).to.be.true; - expect(key.ctrl).to.be.true; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("X"); + expect(key.shift).toBeTruthy; + expect(key.ctrl).toBeTruthy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); it("returns for Shift+Esc", () => { const key = Key.fromMapKey("<S-Esc>"); - expect(key.key).to.equal("Esc"); - expect(key.shift).to.be.true; - expect(key.ctrl).to.be.false; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("Esc"); + expect(key.shift).toBeTruthy; + expect(key.ctrl).toBeFalsy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); it("returns for Ctrl+Esc", () => { const key = Key.fromMapKey("<C-Esc>"); - expect(key.key).to.equal("Esc"); - expect(key.shift).to.be.false; - expect(key.ctrl).to.be.true; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("Esc"); + expect(key.shift).toBeFalsy; + expect(key.ctrl).toBeTruthy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); it("returns for Ctrl+Esc", () => { const key = Key.fromMapKey("<C-Space>"); - expect(key.key).to.equal("Space"); - expect(key.shift).to.be.false; - expect(key.ctrl).to.be.true; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("Space"); + expect(key.shift).toBeFalsy; + expect(key.ctrl).toBeTruthy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); }); describe("idDigit", () => { it("returns true if the key is a digit", () => { - expect(new Key({ key: "0" }).isDigit()).to.be.true; - expect(new Key({ key: "9" }).isDigit()).to.be.true; - expect(new Key({ key: "9", alt: true }).isDigit()).to.be.false; + expect(new Key({ key: "0" }).isDigit()).toBeTruthy; + expect(new Key({ key: "9" }).isDigit()).toBeTruthy; + expect(new Key({ key: "9", alt: true }).isDigit()).toBeFalsy; - expect(new Key({ key: "a" }).isDigit()).to.be.false; - expect(new Key({ key: "0" }).isDigit()).to.be.false; + expect(new Key({ key: "a" }).isDigit()).toBeFalsy; + expect(new Key({ key: "0" }).isDigit()).toBeFalsy; }); }); @@ -105,7 +104,7 @@ describe("Key", () => { meta: false, }) ) - ).to.be.true; + ).toBeTruthy; expect( new Key({ @@ -123,7 +122,7 @@ describe("Key", () => { meta: false, }) ) - ).to.be.false; + ).toBeFalsy; }); }); }); diff --git a/test/shared/settings/Keymaps.test.ts b/test/shared/settings/Keymaps.test.ts index 264684d..850e327 100644 --- a/test/shared/settings/Keymaps.test.ts +++ b/test/shared/settings/Keymaps.test.ts @@ -1,11 +1,10 @@ import Keymaps from "../../../src/shared/settings/Keymaps"; -import { expect } from "chai"; describe("Keymaps", () => { describe("#valueOf", () => { it("returns empty object by empty settings", () => { const keymaps = Keymaps.fromJSON({}).toJSON(); - expect(keymaps).to.be.empty; + expect(keymaps).toEqual({}); }); it("returns keymaps by valid settings", () => { @@ -14,11 +13,11 @@ describe("Keymaps", () => { j: { type: "scroll.vertically", count: 1 }, }).toJSON(); - expect(keymaps["k"]).to.deep.equal({ + expect(keymaps["k"]).toEqual({ type: "scroll.vertically", count: -1, }); - expect(keymaps["j"]).to.deep.equal({ + expect(keymaps["j"]).toEqual({ type: "scroll.vertically", count: 1, }); @@ -29,7 +28,7 @@ describe("Keymaps", () => { Keymaps.fromJSON({ k: { type: "invalid.operation" }, }) - ).to.throw(TypeError); + ).toThrow(TypeError); }); }); @@ -48,7 +47,7 @@ describe("Keymaps", () => { const entries = keymaps .entries() .sort(([name1], [name2]) => name1.localeCompare(name2)); - expect(entries).deep.equals([ + expect(entries).toEqual([ ["j", { type: "scroll.vertically", count: 1 }], ["k", { type: "scroll.vertically", count: -1 }], ["n", { type: "find.next" }], @@ -70,7 +69,7 @@ describe("Keymaps", () => { const entries = keymaps .entries() .sort(([name1], [name2]) => name1.localeCompare(name2)); - expect(entries).deep.equals([ + expect(entries).toEqual([ ["j", { type: "find.prev" }], ["k", { type: "scroll.vertically", count: -1 }], ["n", { type: "find.next" }], diff --git a/test/shared/settings/Properties.test.ts b/test/shared/settings/Properties.test.ts index 647cb1c..1161b48 100644 --- a/test/shared/settings/Properties.test.ts +++ b/test/shared/settings/Properties.test.ts @@ -1,12 +1,11 @@ import Properties from "../../../src/shared/settings/Properties"; -import { expect } from "chai"; import ColorScheme from "../../../src/shared/ColorScheme"; describe("Properties", () => { describe("#propertiesValueOf", () => { it("returns with default properties by empty settings", () => { const props = Properties.fromJSON({}); - expect(props).to.deep.equal({ + expect(props).toEqual({ hintchars: "abcdefghijklmnopqrstuvwxyz", smoothscroll: false, complete: "sbh", @@ -22,7 +21,7 @@ describe("Properties", () => { colorscheme: ColorScheme.System, }); - expect(props).to.deep.equal({ + expect(props).toEqual({ hintchars: "abcdefgh", smoothscroll: false, complete: "sbh", diff --git a/test/shared/settings/Search.test.ts b/test/shared/settings/Search.test.ts index 1feb14b..5d2f8d5 100644 --- a/test/shared/settings/Search.test.ts +++ b/test/shared/settings/Search.test.ts @@ -1,5 +1,4 @@ import Search from "../../../src/shared/settings/Search"; -import { expect } from "chai"; describe("Search", () => { it("returns search settings by valid settings", () => { @@ -11,12 +10,12 @@ describe("Search", () => { }, }); - expect(search.defaultEngine).to.equal("google"); - expect(search.engines).to.deep.equals({ + expect(search.defaultEngine).toEqual("google"); + expect(search.engines).toEqual({ google: "https://google.com/search?q={}", yahoo: "https://search.yahoo.com/search?p={}", }); - expect(search.toJSON()).to.deep.equal({ + expect(search.toJSON()).toEqual({ default: "google", engines: { google: "https://google.com/search?q={}", @@ -34,7 +33,7 @@ describe("Search", () => { yahoo: "https://search.yahoo.com/search?p={}", }, }) - ).to.throw(TypeError); + ).toThrow(TypeError); expect(() => Search.fromJSON({ default: "g o o g l e", @@ -42,7 +41,7 @@ describe("Search", () => { "g o o g l e": "https://google.com/search?q={}", }, }) - ).to.throw(TypeError); + ).toThrow(TypeError); expect(() => Search.fromJSON({ default: "google", @@ -50,7 +49,7 @@ describe("Search", () => { google: "https://google.com/search", }, }) - ).to.throw(TypeError); + ).toThrow(TypeError); expect(() => Search.fromJSON({ default: "google", @@ -58,6 +57,6 @@ describe("Search", () => { google: "https://google.com/search?q={}&r={}", }, }) - ).to.throw(TypeError); + ).toThrow(TypeError); }); }); diff --git a/test/shared/settings/Settings.test.ts b/test/shared/settings/Settings.test.ts index 951c9cd..49a5d0b 100644 --- a/test/shared/settings/Settings.test.ts +++ b/test/shared/settings/Settings.test.ts @@ -1,5 +1,4 @@ import Settings from "../../../src/shared/settings/Settings"; -import { expect } from "chai"; describe("Settings", () => { describe("#valueOf", () => { @@ -21,7 +20,7 @@ describe("Settings", () => { search: x.search.toJSON(), properties: x.properties.toJSON(), blacklist: x.blacklist.toJSON(), - }).to.deep.equal({ + }).toEqual({ keymaps: {}, search: { default: "google", @@ -41,15 +40,15 @@ describe("Settings", () => { it("sets default settings", () => { const value = Settings.fromJSON({}); - expect(value.keymaps.toJSON()).to.not.be.empty; - expect(value.properties.toJSON()).to.not.be.empty; - expect(value.search.defaultEngine).to.be.a("string"); - expect(value.search.engines).to.be.an("object"); - expect(value.blacklist.toJSON()).to.be.empty; + expect(value.keymaps.toJSON()).not.toEqual({}); + expect(value.properties.toJSON()).not.toEqual({}); + expect(typeof value.search.defaultEngine).toEqual("string"); + expect(typeof value.search.engines).toEqual("object"); + expect(value.blacklist.toJSON()).toHaveLength(0); }); it("throws a TypeError with an unknown field", () => { - expect(() => Settings.fromJSON({ name: "alice" })).to.throw(TypeError); + expect(() => Settings.fromJSON({ name: "alice" })).toThrow(TypeError); }); }); }); diff --git a/test/shared/urls.test.ts b/test/shared/urls.test.ts index f264ad9..ec618f6 100644 --- a/test/shared/urls.test.ts +++ b/test/shared/urls.test.ts @@ -1,5 +1,4 @@ import * as parsers from "../../src/shared/urls"; -import { expect } from "chai"; import Search from "../../src/shared/settings/Search"; describe("shared/commands/parsers", () => { @@ -13,55 +12,55 @@ describe("shared/commands/parsers", () => { }); it("convertes search url", () => { - expect(parsers.searchUrl("google.com", config)).to.equal( + expect(parsers.searchUrl("google.com", config)).toEqual( "http://google.com" ); - expect(parsers.searchUrl("google apple", config)).to.equal( + expect(parsers.searchUrl("google apple", config)).toEqual( "https://google.com/search?q=apple" ); - expect(parsers.searchUrl("yahoo apple", config)).to.equal( + expect(parsers.searchUrl("yahoo apple", config)).toEqual( "https://yahoo.com/search?q=apple" ); - expect(parsers.searchUrl("google apple banana", config)).to.equal( + expect(parsers.searchUrl("google apple banana", config)).toEqual( "https://google.com/search?q=apple%20banana" ); - expect(parsers.searchUrl("yahoo C++CLI", config)).to.equal( + expect(parsers.searchUrl("yahoo C++CLI", config)).toEqual( "https://yahoo.com/search?q=C%2B%2BCLI" ); }); it("user default search engine", () => { - expect(parsers.searchUrl("apple banana", config)).to.equal( + expect(parsers.searchUrl("apple banana", config)).toEqual( "https://google.com/search?q=apple%20banana" ); }); it("searches with a word containing a colon", () => { - expect(parsers.searchUrl("foo:", config)).to.equal( + expect(parsers.searchUrl("foo:", config)).toEqual( "https://google.com/search?q=foo%3A" ); - expect(parsers.searchUrl("std::vector", config)).to.equal( + expect(parsers.searchUrl("std::vector", config)).toEqual( "https://google.com/search?q=std%3A%3Avector" ); }); it("localhost urls", () => { - expect(parsers.searchUrl("localhost", config)).to.equal( + expect(parsers.searchUrl("localhost", config)).toEqual( "http://localhost" ); - expect(parsers.searchUrl("http://localhost", config)).to.equal( + expect(parsers.searchUrl("http://localhost", config)).toEqual( "http://localhost/" ); - expect(parsers.searchUrl("localhost:8080", config)).to.equal( + expect(parsers.searchUrl("localhost:8080", config)).toEqual( "http://localhost:8080" ); - expect(parsers.searchUrl("localhost:80nan", config)).to.equal( + expect(parsers.searchUrl("localhost:80nan", config)).toEqual( "https://google.com/search?q=localhost%3A80nan" ); - expect(parsers.searchUrl("localhost 8080", config)).to.equal( + expect(parsers.searchUrl("localhost 8080", config)).toEqual( "https://google.com/search?q=localhost%208080" ); - expect(parsers.searchUrl("localhost:80/build", config)).to.equal( + expect(parsers.searchUrl("localhost:80/build", config)).toEqual( "http://localhost:80/build" ); }); @@ -69,10 +68,10 @@ describe("shared/commands/parsers", () => { describe("#normalizeUrl", () => { it("normalize urls", () => { - expect(parsers.normalizeUrl("https://google.com/")).to.equal( + expect(parsers.normalizeUrl("https://google.com/")).toEqual( "https://google.com/" ); - expect(parsers.normalizeUrl("google.com")).to.equal("http://google.com"); + expect(parsers.normalizeUrl("google.com")).toEqual("http://google.com"); }); }); }); |