vitest#afterAll TypeScript Examples

The following examples show how to use vitest#afterAll. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: get-gas.spec.ts    From cloud-cryptographic-wallet with MIT License 5 votes vote down vote up
describe("getGas", () => {
  const rpcUrl = "http://locahost:8545";

  const server = getServer(rpcUrl, []);
  const txParams = { from: "0x9f60980a13f74d79214E258D2F52Fd846A3a5511" };

  beforeAll(() => server.listen());
  afterEach(() => server.resetHandlers());
  afterAll(() => server.close());

  describe("when return gas", () => {
    const gas = "0x5208";

    beforeEach(() => {
      server.use(
        makeHandler(rpcUrl, {
          method: "eth_estimateGas",
          result: gas,
        })
      );
    });

    it("shoud be get gas", async () => {
      await expect(getGas(rpcUrl, txParams)).resolves.toBe(gas);
    });
  });
  describe("when return null", () => {
    beforeEach(() => {
      server.use(
        makeHandler(rpcUrl, {
          method: "eth_estimateGas",
          result: null,
        })
      );
    });

    it("shoud be throw error", async () => {
      await expect(getGas(rpcUrl, txParams)).rejects.toThrow(
        /can't get result of eth_estimateGas/
      );
    });
  });
});
Example #2
Source File: get-nonce.spec.ts    From cloud-cryptographic-wallet with MIT License 5 votes vote down vote up
describe("getNonce", () => {
  const rpcUrl = "http://locahost:8545";
  const from = "0x9f60980a13f74d79214E258D2F52Fd846A3a5511";

  const server = getServer(rpcUrl, []);

  beforeAll(() => server.listen());
  afterEach(() => server.resetHandlers());
  afterAll(() => server.close());

  describe("when return nonce", () => {
    const nonce = "0x10";
    beforeEach(() => {
      server.use(
        makeHandler(rpcUrl, {
          method: "eth_getTransactionCount",
          result: nonce,
        })
      );
    });

    it("shoud be get nonce", async () => {
      await expect(getNonce(rpcUrl, from)).resolves.toBe(nonce);
    });
  });

  describe("when return null", () => {
    beforeEach(() => {
      server.use(
        makeHandler(rpcUrl, {
          method: "eth_getTransactionCount",
          result: null,
        })
      );
    });

    it("shoud be throw error", async () => {
      await expect(getNonce(rpcUrl, from)).rejects.toThrow(
        /can't get result of eth_getTransactionCount/
      );
    });
  });
});
Example #3
Source File: get-common.spec.ts    From cloud-cryptographic-wallet with MIT License 5 votes vote down vote up
describe("getCommon", () => {
  const rpcUrl = "http://locahost:8545";

  const server = getServer(rpcUrl, []);

  beforeAll(() => server.listen());
  afterEach(() => server.resetHandlers());
  afterAll(() => server.close());

  describe("when return gas", () => {
    const chainId = "0x1";

    beforeEach(() => {
      server.use(
        makeHandler(rpcUrl, {
          method: "eth_chainId",
          result: chainId,
        })
      );
    });

    it("shoud be get common", async () => {
      const common = await getCommon(rpcUrl);

      expect(`0x${common.chainIdBN().toString("hex")}`).toBe(chainId);
    });
  });
  describe("when return null", () => {
    beforeEach(() => {
      server.use(
        makeHandler(rpcUrl, {
          method: "eth_estimateGas",
          result: null,
        })
      );
    });

    it("shoud be throw error", async () => {
      await expect(getCommon(rpcUrl)).rejects.toThrow(
        /can't get result of eth_chainId/
      );
    });
  });
});
Example #4
Source File: vitest.setup.ts    From v-perfect-signature with MIT License 5 votes vote down vote up
afterAll(() => {
  // @ts-expect-error: type
  delete global.jest
  // @ts-expect-error: type
  delete global.window.jest
})