aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2021-09-26 14:15:33 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2021-09-26 16:12:58 +0900
commit84df6f233677a16f8a3f84b3eb7e77923da2c7fa (patch)
treefd397824d5295d4e38a6412d3faa1f06214a839b
parente1b4a2dc6763966628bc4a29838c48022cd5b4e5 (diff)
Use jest API and fix some tests
-rw-r--r--test/background/usecases/SettingUseCase.test.ts36
-rw-r--r--test/console/completion/reducer.test.ts12
-rw-r--r--test/console/components/console/Completion.test.tsx18
-rw-r--r--test/content/presenters/Hint.test.ts8
-rw-r--r--test/content/presenters/NavigationPresenter.test.ts6
-rw-r--r--test/content/repositories/FollowKeyRepository.test.ts2
-rw-r--r--test/content/repositories/FollowMasterRepository.test.ts2
-rw-r--r--test/content/repositories/FollowSlaveRepository.test.ts2
-rw-r--r--test/content/repositories/KeymapRepository.test.ts2
-rw-r--r--test/content/repositories/MarkKeyRepository.test.ts2
-rw-r--r--test/content/usecases/AddonEnabledUseCase.test.ts2
-rw-r--r--test/content/usecases/KeymapUseCase.test.ts18
12 files changed, 53 insertions, 57 deletions
diff --git a/test/background/usecases/SettingUseCase.test.ts b/test/background/usecases/SettingUseCase.test.ts
index 8a4c2b2..54b6711 100644
--- a/test/background/usecases/SettingUseCase.test.ts
+++ b/test/background/usecases/SettingUseCase.test.ts
@@ -87,7 +87,7 @@ describe("SettingUseCase", () => {
});
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,
@@ -116,7 +116,7 @@ describe("SettingUseCase", () => {
});
});
- 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,
@@ -145,23 +145,21 @@ describe("SettingUseCase", () => {
});
});
- 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 () => {
+ 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
+ );
});
});
});
diff --git a/test/console/completion/reducer.test.ts b/test/console/completion/reducer.test.ts
index b742872..91a6751 100644
--- a/test/console/completion/reducer.test.ts
+++ b/test/console/completion/reducer.test.ts
@@ -65,14 +65,14 @@ 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);
});
});
- context("when no completion items", () => {
+ describe("when no completion items", () => {
it("does nothing", () => {
const state = {
...defaultState,
@@ -83,7 +83,7 @@ describe("completion reducer", () => {
});
});
- context("when completions exist", () => {
+ describe("when completions exist", () => {
it("selects next selection", () => {
let state: State = {
...defaultState,
@@ -116,13 +116,13 @@ describe("completion reducer", () => {
});
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);
});
- context("when no completion items", () => {
+ describe("when no completion items", () => {
it("does nothing", () => {
const state = {
...defaultState,
@@ -134,7 +134,7 @@ describe("completion reducer", () => {
});
});
- context("when completions exist", () => {
+ describe("when completions exist", () => {
it("selects a previous completion", () => {
let state: State = {
...defaultState,
diff --git a/test/console/components/console/Completion.test.tsx b/test/console/components/console/Completion.test.tsx
index 9b47637..063b1e3 100644
--- a/test/console/components/console/Completion.test.tsx
+++ b/test/console/components/console/Completion.test.tsx
@@ -100,7 +100,7 @@ describe("console/components/console/completion/Completion", () => {
});
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 +108,7 @@ describe("console/components/console/completion/Completion", () => {
);
});
- const root = component.root;
+ const root = component!.root;
let items = root.findAllByType(CompletionItem);
let showns = root
@@ -132,7 +132,7 @@ describe("console/components/console/completion/Completion", () => {
]);
ReactTestRenderer.act(() => {
- component.update(
+ component!.update(
<Completion completions={completions} size={3} select={2} />
);
});
@@ -159,7 +159,7 @@ describe("console/components/console/completion/Completion", () => {
expect(items[2].props.highlight).to.be.true;
ReactTestRenderer.act(() => {
- component.update(
+ component!.update(
<Completion completions={completions} size={3} select={3} />
);
});
@@ -187,14 +187,14 @@ describe("console/components/console/completion/Completion", () => {
});
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
@@ -220,7 +220,7 @@ describe("console/components/console/completion/Completion", () => {
expect(items[5].props.highlight).to.be.true;
ReactTestRenderer.act(() => {
- component.update(
+ component!.update(
<Completion completions={completions} size={3} select={4} />
);
});
@@ -247,7 +247,7 @@ describe("console/components/console/completion/Completion", () => {
expect(items[4].props.highlight).to.be.true;
ReactTestRenderer.act(() => {
- component.update(
+ component!.update(
<Completion completions={completions} size={3} select={3} />
);
});
@@ -274,7 +274,7 @@ describe("console/components/console/completion/Completion", () => {
expect(items[3].props.highlight).to.be.true;
ReactTestRenderer.act(() => {
- component.update(
+ component!.update(
<Completion completions={completions} size={3} select={2} />
);
});
diff --git a/test/content/presenters/Hint.test.ts b/test/content/presenters/Hint.test.ts
index e9be2d5..0823bdc 100644
--- a/test/content/presenters/Hint.test.ts
+++ b/test/content/presenters/Hint.test.ts
@@ -108,7 +108,7 @@ describe("LinkHint", () => {
describe("InputHint", () => {
describe("#activate()", () => {
- context("<input>", () => {
+ describe("<input>", () => {
beforeEach(() => {
document.body.innerHTML = `<input id='test-input'></input>`;
});
@@ -122,7 +122,7 @@ describe("InputHint", () => {
});
});
- context('<input type="checkbox">', () => {
+ describe('<input type="checkbox">', () => {
beforeEach(() => {
document.body.innerHTML = `<input type="checkbox" id='test-input'></input>`;
});
@@ -135,7 +135,7 @@ describe("InputHint", () => {
expect(input.checked).to.be.true;
});
});
- context("<textarea>", () => {
+ describe("<textarea>", () => {
beforeEach(() => {
document.body.innerHTML = `<textarea id='test-textarea'></textarea>`;
});
@@ -151,7 +151,7 @@ describe("InputHint", () => {
});
});
- 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 74466ae..c377df4 100644
--- a/test/content/presenters/NavigationPresenter.test.ts
+++ b/test/content/presenters/NavigationPresenter.test.ts
@@ -5,9 +5,7 @@
import { NavigationPresenterImpl } from "../../../src/content/presenters/NavigationPresenter";
import { expect } from "chai";
-describe("NavigationPresenterImpl", function () {
- this.timeout(5000);
-
+describe("NavigationPresenterImpl", () => {
let sut: NavigationPresenterImpl;
const testRel = (done: () => void, rel: string, html: string) => {
@@ -25,7 +23,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/FollowKeyRepository.test.ts b/test/content/repositories/FollowKeyRepository.test.ts
index 6608662..cf1d3d5 100644
--- a/test/content/repositories/FollowKeyRepository.test.ts
+++ b/test/content/repositories/FollowKeyRepository.test.ts
@@ -6,7 +6,7 @@ import { expect } from "chai";
describe("FollowKeyRepositoryImpl", () => {
let sut: FollowKeyRepository;
- before(() => {
+ beforeEach(() => {
sut = new FollowKeyRepositoryImpl();
});
diff --git a/test/content/repositories/FollowMasterRepository.test.ts b/test/content/repositories/FollowMasterRepository.test.ts
index 9b5e151..8e1d59e 100644
--- a/test/content/repositories/FollowMasterRepository.test.ts
+++ b/test/content/repositories/FollowMasterRepository.test.ts
@@ -6,7 +6,7 @@ import { expect } from "chai";
describe("FollowMasterRepositoryImpl", () => {
let sut: FollowMasterRepository;
- before(() => {
+ beforeEach(() => {
sut = new FollowMasterRepositoryImpl();
});
diff --git a/test/content/repositories/FollowSlaveRepository.test.ts b/test/content/repositories/FollowSlaveRepository.test.ts
index 0f829b2..c19513d 100644
--- a/test/content/repositories/FollowSlaveRepository.test.ts
+++ b/test/content/repositories/FollowSlaveRepository.test.ts
@@ -6,7 +6,7 @@ import { expect } from "chai";
describe("FollowSlaveRepository", () => {
let sut: FollowSlaveRepository;
- before(() => {
+ beforeEach(() => {
sut = new FollowSlaveRepositoryImpl();
});
diff --git a/test/content/repositories/KeymapRepository.test.ts b/test/content/repositories/KeymapRepository.test.ts
index 0e01a73..7321548 100644
--- a/test/content/repositories/KeymapRepository.test.ts
+++ b/test/content/repositories/KeymapRepository.test.ts
@@ -7,7 +7,7 @@ import Key from "../../../src/shared/settings/Key";
describe("KeymapRepositoryImpl", () => {
let sut: KeymapRepository;
- before(() => {
+ beforeEach(() => {
sut = new KeymapRepositoryImpl();
});
diff --git a/test/content/repositories/MarkKeyRepository.test.ts b/test/content/repositories/MarkKeyRepository.test.ts
index 473b4dc..317bbaa 100644
--- a/test/content/repositories/MarkKeyRepository.test.ts
+++ b/test/content/repositories/MarkKeyRepository.test.ts
@@ -6,7 +6,7 @@ import { expect } from "chai";
describe("MarkKeyRepositoryImpl", () => {
let sut: MarkRepository;
- before(() => {
+ beforeEach(() => {
sut = new MarkKeyRepositoryImpl();
});
diff --git a/test/content/usecases/AddonEnabledUseCase.test.ts b/test/content/usecases/AddonEnabledUseCase.test.ts
index 8a614c5..ee5f1cd 100644
--- a/test/content/usecases/AddonEnabledUseCase.test.ts
+++ b/test/content/usecases/AddonEnabledUseCase.test.ts
@@ -56,7 +56,7 @@ describe("AddonEnabledUseCase", () => {
});
});
- describe("#disable", async () => {
+ describe("#disable", () => {
it("store and indicate as disabled", async () => {
await sut.disable();
diff --git a/test/content/usecases/KeymapUseCase.test.ts b/test/content/usecases/KeymapUseCase.test.ts
index 24ac6d8..22b09ac 100644
--- a/test/content/usecases/KeymapUseCase.test.ts
+++ b/test/content/usecases/KeymapUseCase.test.ts
@@ -41,7 +41,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 +52,7 @@ describe("KeymapUseCase", () => {
let sut: KeymapUseCase;
- before(() => {
+ beforeEach(() => {
sut = new KeymapUseCase(
new KeymapRepositoryImpl(),
new MockSettingRepository(settings),
@@ -89,7 +89,7 @@ describe("KeymapUseCase", () => {
});
});
- context("when keymaps containing numeric mappings", () => {
+ describe("when keymaps containing numeric mappings", () => {
const settings = Settings.fromJSON({
keymaps: {
20: { type: "scroll.top" },
@@ -99,7 +99,7 @@ describe("KeymapUseCase", () => {
let sut: KeymapUseCase;
- before(() => {
+ beforeEach(() => {
sut = new KeymapUseCase(
new KeymapRepositoryImpl(),
new MockSettingRepository(settings),
@@ -145,7 +145,7 @@ describe("KeymapUseCase", () => {
});
});
- 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 +155,7 @@ describe("KeymapUseCase", () => {
let sut: KeymapUseCase;
- before(() => {
+ beforeEach(() => {
sut = new KeymapUseCase(
new KeymapRepositoryImpl(),
new MockSettingRepository(settings),
@@ -189,7 +189,7 @@ describe("KeymapUseCase", () => {
});
});
- 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 +200,7 @@ describe("KeymapUseCase", () => {
let sut: KeymapUseCase;
- before(() => {
+ beforeEach(() => {
sut = new KeymapUseCase(
new KeymapRepositoryImpl(),
new MockSettingRepository(settings),
@@ -222,7 +222,7 @@ describe("KeymapUseCase", () => {
});
});
- 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 },