UPDATE My test:
let wrapper;
beforeEach(() => {
// use this to check the state of anything in the view
wrapper = shallowMount(NFTMintComponent);
});
it('getData function should affect the cost and totalSupply to the data', async () => {
//window.ethereum = jest.fn();
//const window_ethereum = 'window_ethereum_test';
//window.ethereum.mockResolvedValue(window_ethereum);
window.ethereum = [];
window.ethereum.request = jest.fn();
const accounts = ['0xe14d2f7105f759a100eab6559282083e0d5760ff'];
window.ethereum.request.mockResolvedValue(accounts);
let ethers = {
providers: {
Web3Provider: jest.fn()
},
Contract: jest.fn()
}
const provider = 'ropsten';
ethers.providers.Web3Provider.mockResolvedValue(provider);
const contractMocked = 'contract';
ethers.Contract.mockResolvedValue(contractMocked);
let contract = {
cost: jest.fn(),
totalSupply: jest.fn()
};
const costMocked = 5;
const totalSupplyMocked = 50;
contract.cost.mockResolvedValue(costMocked);
contract.totalSupply.mockResolvedValue(totalSupplyMocked);
await wrapper.vm.getData();
//console.log(wrapper.vm.data);
expect(wrapper.vm.data.cost).toBe('5');
expect(wrapper.vm.data.totalSupply).toBe('50');
});
My test enter into the 'try' but stops at const cost = await contract.cost(); with the following error: Could not detect network ... event: 'invalidNetwork' reason 'invalid BigNumber value'
I think I don't mocked well my ethers.providers.Web3Provider or my ethers.Contract.
How to mock the provider and the contract ?