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/console | |
| parent | 24f4f06db6572d81cadfe191f36c433a79985871 (diff) | |
| parent | 039095e18562c44edda2c5a83a3d82c2e220b370 (diff) | |
Merge pull request #1267 from ueokande/move-to-jest
Move to Jest
Diffstat (limited to 'test/console')
| -rw-r--r-- | test/console/app/actions.test.ts | 25 | ||||
| -rw-r--r-- | test/console/app/reducer.test.ts | 21 | ||||
| -rw-r--r-- | test/console/commandline/CommandLineParser.test.ts | 13 | ||||
| -rw-r--r-- | test/console/commandline/CommandParser.test.ts | 9 | ||||
| -rw-r--r-- | test/console/completion/reducer.test.ts | 43 | ||||
| -rw-r--r-- | test/console/components/ErrorMessage.test.tsx | 7 | ||||
| -rw-r--r-- | test/console/components/InfoMessage.test.tsx | 7 | ||||
| -rw-r--r-- | test/console/components/console/Completion.test.tsx | 61 | ||||
| -rw-r--r-- | test/console/components/console/CompletionItem.test.tsx | 7 | ||||
| -rw-r--r-- | test/console/components/console/CompletionTitle.test.tsx | 3 | 
10 files changed, 90 insertions, 106 deletions
| 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"]);    });  }); | 
