aboutsummaryrefslogtreecommitdiff
path: root/test/background/completion/OpenCompletionUseCase.test.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2021-10-10 01:42:37 +0000
committerGitHub <noreply@github.com>2021-10-10 01:42:37 +0000
commitdfcefe1b84cc96ead1c8d8f9aa65ff05ccd70378 (patch)
tree12f1a4ed6da8fd96c034d23bcf08b1535bca1113 /test/background/completion/OpenCompletionUseCase.test.ts
parent24f4f06db6572d81cadfe191f36c433a79985871 (diff)
parent039095e18562c44edda2c5a83a3d82c2e220b370 (diff)
Merge pull request #1267 from ueokande/move-to-jest
Move to Jest
Diffstat (limited to 'test/background/completion/OpenCompletionUseCase.test.ts')
-rw-r--r--test/background/completion/OpenCompletionUseCase.test.ts102
1 files changed, 47 insertions, 55 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");
});
});
});