vitest#afterEach TypeScript Examples

The following examples show how to use vitest#afterEach. 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: createMindmap.test.ts    From remind with MIT License 5 votes vote down vote up
afterEach(() => {
  container.remove()
})
Example #2
Source File: useEventListener.test.ts    From remind with MIT License 5 votes vote down vote up
afterEach(() => {
  container.remove()
})
Example #3
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 #4
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 #5
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 #6
Source File: controller.test.ts    From d3-graph-controller with MIT License 4 votes vote down vote up
describe('GraphController', () => {
  let container: HTMLDivElement
  let controller: GraphController<TestNodeType>

  beforeEach(() => {
    container = document.createElement('div')
    controller = new GraphController(container, TestData.graph, TestData.config)
  })

  afterEach(() => controller.shutdown())

  it('matches the snapshot', () => {
    expect(container).toMatchSnapshot()
  })

  it('renders nodes', () => {
    expect(container.querySelectorAll('.node').length).toEqual(
      TestData.graph.nodes.length
    )
  })

  it('renders links', () => {
    expect(container.querySelectorAll('.link').length).toEqual(
      TestData.graph.links.length
    )
  })

  describe('can be configured', () => {
    describe('with initial settings', () => {
      it('that set the node type filter', () => {
        controller = new GraphController(
          container,
          TestData.graph,
          defineGraphConfig<TestNodeType>({ initial: { nodeTypeFilter: [] } })
        )

        expect(controller.nodeTypeFilter).toEqual([])
        expect(container.querySelectorAll('.node').length).toEqual(0)
        expect(container.querySelectorAll('.link').length).toEqual(0)
      })

      it('that exclude unlinked nodes', () => {
        controller = new GraphController(
          container,
          TestData.graph,
          defineGraphConfig<TestNodeType>({
            initial: { includeUnlinked: false },
          })
        )

        expect(controller.includeUnlinked).toEqual(false)
        expect(container.querySelectorAll('.node').length).toEqual(3)
      })

      it('that filter links', () => {
        controller = new GraphController(
          container,
          TestData.graph,
          defineGraphConfig<TestNodeType>({
            initial: {
              linkFilter: (link: GraphLink<TestNodeType>) =>
                link.source.id === link.target.id,
            },
          })
        )

        expect(container.querySelectorAll('.link').length).toEqual(1)
      })
    })
  })

  describe('has settings that', () => {
    it('can exclude unlinked nodes', () => {
      expect(container.querySelectorAll('.node').length).toEqual(
        TestData.graph.nodes.length
      )

      controller.includeUnlinked = false

      expect(container.querySelectorAll('.node').length).toEqual(3)
    })

    it('can filter links', () => {
      expect(container.querySelectorAll('.link').length).toEqual(
        TestData.graph.links.length
      )

      controller.linkFilter = (link: GraphLink<TestNodeType>) =>
        link.source.id === link.target.id

      expect(container.querySelectorAll('.link').length).toEqual(1)
    })

    it('can filter by node type', () => {
      const currentlyExcluded: TestNodeType[] = []

      const checkIncludedNodes = () => {
        expect(container.querySelectorAll('.node').length).toEqual(
          TestData.graph.nodes.filter(
            (node) => !currentlyExcluded.includes(node.type)
          ).length
        )
      }

      checkIncludedNodes()

      controller.filterNodesByType(false, 'second')
      currentlyExcluded.push('second')
      checkIncludedNodes()

      controller.filterNodesByType(false, 'first')
      currentlyExcluded.push('first')
      checkIncludedNodes()

      controller.filterNodesByType(true, 'first')
      currentlyExcluded.pop()
      checkIncludedNodes()

      controller.filterNodesByType(true, 'second')
      currentlyExcluded.pop()
      checkIncludedNodes()
    })
  })
})