我正在尝试为下面的函数调用编写模拟测试
const contract = await new web3.eth.Contract();
tx.data = await contract.methods
.setup(
[juryAddress, buyerAddress, sellerAddress],
threshold,
to,
txData,
fallbackHandler,
paymentToken,
0,
sellerAddress
)
.encodeABI();
我试图将其模拟为一个函数contract.methods.setup()
,它返回一个函数对象encodeABI()
,然后返回一个伪值{}
。
我正在尝试的模拟看起来像这样,虽然它不工作
const encodeABI = jest.fn()
encodeABI.mockReturnValue({})
const contract = {
methods: {
setup: jest.fn(),
}
}
eth.Contract.mockResolvedValue(contract)
contract.methods.setup.mockResolvedValue(encodeABI)
expect(encodeABI).toBeCalled()
未按预期调用expect(encodeABI).toBeCalled()
1条答案
按热度按时间g52tjvyc1#
您的生产代码等待
encodeABI()
,而不是setup()
。它期望setup()
返回一个带有encodeABI()
函数的对象,而不是Promise
。我建议进行以下更改