diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2021-09-26 17:01:31 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2021-09-26 17:23:14 +0900 |
commit | e304581fb15eabb3a973d363a282ee7546561e01 (patch) | |
tree | 1afb21a2dee2ada3d10c1417fa61c0aae1f83077 /test/content/usecases | |
parent | 11d6d725eee2ac0a1c16e4c7a4ce4f296bb6b016 (diff) |
Do not use chai on unit test
Diffstat (limited to 'test/content/usecases')
-rw-r--r-- | test/content/usecases/AddonEnabledUseCase.test.ts | 29 | ||||
-rw-r--r-- | test/content/usecases/HintKeyProducer.test.ts | 13 | ||||
-rw-r--r-- | test/content/usecases/KeymapUseCase.test.ts | 89 | ||||
-rw-r--r-- | test/content/usecases/MarkUseCase.test.ts | 15 | ||||
-rw-r--r-- | test/content/usecases/SettingUseCaase.test.ts | 5 |
5 files changed, 73 insertions, 78 deletions
diff --git a/test/content/usecases/AddonEnabledUseCase.test.ts b/test/content/usecases/AddonEnabledUseCase.test.ts index ee5f1cd..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,9 +49,9 @@ 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; }); }); @@ -60,9 +59,9 @@ describe("AddonEnabledUseCase", () => { 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 22b09ac..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"; @@ -62,27 +61,27 @@ 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" }, }); @@ -109,36 +108,36 @@ 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" }, }); @@ -165,24 +164,24 @@ 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" }, }); @@ -210,12 +209,12 @@ 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" }, }); @@ -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"); }); }); }); |