smartcontractkit / full-blockchain-solidity-course-js

Learn Blockchain, Solidity, and Full Stack Web3 Development with Javascript
12.25k stars 2.94k forks source link

Lesson06-test-deploy.js:TypeError: Test argument "title" should be a string. Received type "undefined" #4893

Closed Minomeis closed 1 year ago

Minomeis commented 1 year ago

I'm trying to run

yarn hardhat test

here is my code

const { assert } = require("chai")
const { ethers } = require("hardhat")

describe("SimpleStorage", function () {

    let simpleStorageFactory, simpleStorage

    beforeEach(async function () {
        simpleStorageFactory = await ethers.getContracttFactory(
            "SinmpleStorage"
        )
        simpleStorage = await simpleStorageFactory.deploy()
    })
    it("Shoule start with a favorite number of 0", async function () {
        const currentValue = await simpleStorage.retrieve()
        const expectedValue = "0"
        // expect
        assert.equal(currentValue.toString(), expectedValue)
    })
    // it()
})

And this is the error

yarn run v1.22.19
$ /home/minomeis/hh-fcc/hardhat-simple-storage-fcc/node_modules/.bin/hardhat test
An unexpected error occurred:

TypeError: Test argument "title" should be a string. Received type "undefined"
    at createInvalidArgumentTypeError (/home/minomeis/hh-fcc/hardhat-simple-storage-fcc/node_modules/mocha/lib/errors.js:268:13)
    at new Test (/home/minomeis/hh-fcc/hardhat-simple-storage-fcc/node_modules/mocha/lib/test.js:23:11)
    at context.it.context.specify (/home/minomeis/hh-fcc/hardhat-simple-storage-fcc/node_modules/mocha/lib/interfaces/bdd.js:87:18)
    at Suite.<anonymous> (/home/minomeis/hh-fcc/hardhat-simple-storage-fcc/test/test-deploy.js:25:5)
    at Object.create (/home/minomeis/hh-fcc/hardhat-simple-storage-fcc/node_modules/mocha/lib/interfaces/common.js:148:19)
    at context.describe.context.context (/home/minomeis/hh-fcc/hardhat-simple-storage-fcc/node_modules/mocha/lib/interfaces/bdd.js:42:27)
    at Object.<anonymous> (/home/minomeis/hh-fcc/hardhat-simple-storage-fcc/test/test-deploy.js:9:1)
    at Module._compile (node:internal/modules/cjs/loader:1112:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
    at Module.load (node:internal/modules/cjs/loader:988:32) {
  code: 'ERR_MOCHA_INVALID_ARG_TYPE',
  argument: 'title',
  expected: 'string',
  actual: 'string'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I've already search on Google but doesn't find the solution,could somebody can help me? thanks!

Minomeis commented 1 year ago

turns out i have some format problems I try to change this part

    beforeEach(async function () {
        simpleStorageFactory = await ethers.getContracttFactory(
            "SinmpleStorage"
        )
        simpleStorage = await simpleStorageFactory.deploy()
    })

to this

    beforeEach(async function () {
        simpleStorageFactory = await ethers.getContractFactory("SimpleStorage")
        simpleStorage = await simpleStorageFactory.deploy()
    })

the problem solved