0
0

More than 1 year has passed since last update.

Hardhat と mocha でテストをした時に pending で終了してしまう問題

Posted at

hardhat でテストをしている時に pending が発生してテストが実行されませんでした。

  Todo CRUD
    - Should return the new TODO once it's changed


  0 passing (2ms)
  1 pending

使っていたテストコードはこちら。

const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("Todo CRUD", function() {
  it("Should return the new TODO once it's changed"), async function () {
    const Todo = await ethers.getContractFactory("todo");
    const todo = await Todo.deploy();
    await todo.deployed();

    // don't have todo
    expect((await todo.getTODO()).length).to.equal(0);

    const createTodoTx = await todo.createTODO("do my homework");
    await createTodoTx.wait();

    expect((await todo.getTODO()).length).to.equal(1);
  }
});

しかしこのコードは間違っていて It 句が正しく閉じられていませんでした。

const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("Todo CRUD", function() {
- it("Should return the new TODO once it's changed"), async function () {
+ it("Should return the new TODO once it's changed", async function () {
    const Todo = await ethers.getContractFactory("todo");
    const todo = await Todo.deploy();
    await todo.deployed();

    // don't have todo
    expect((await todo.getTODO()).length).to.equal(0);

    const createTodoTx = await todo.createTODO("do my homework");
    await createTodoTx.wait();

    expect((await todo.getTODO()).length).to.equal(1);
  }
- });
+ }));

これでうまく動くように!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0