Property 'mockImplementation' does not exist on type ** => Promise<object>' in jest

Viewed 28

I have tested sample apps in Jest. In this test, my function exec is very heavy so that I would like to mock its response. I set mock as follows


import { IrohaTransactionExec } from "@post-pricing/infrastructure/src/query/monopoly/shoptransactions/transactions/irohaTransactionExec"
jest.mock( "@post-pricing/infrastructure/src/query/monopoly/shoptransactions/transactions/irohaTransactionExec")


const iroha = await new IrohaTransactionExec().exec.mockImplementation(jest.fn().mockReturnValue(irohaResponse))

But it returned following error at mockImplementation. What is the root cause of this?

[{
    "owner": "typescript",
    "code": "2339",
    "severity": 8,
    "message": "Property 'mockImplementation' does not exist on type '(shopCode: string, nptransactionId: string) => Promise<object>'.",
    "source": "ts",
    "startLineNumber": 12,
    "startColumn": 65,
    "endLineNumber": 12,
    "endColumn": 83
}]

exec() is as follows:

import { IrohaClientBuilder,IrohaRequestParam } from "/utility"


export class IrohaTransactionExec {

    private irohaClient:IrohaClientBuilder
    private irohaRequestParam:IrohaRequestParam

    constructor(){
        this.irohaClient =  new IrohaClientBuilder()
        this.irohaRequestParam = new IrohaRequestParam()
    }

    public exec = async (shopCode:string,nptransactionId:string):Promise<object> =>{
        const client = await this.irohaClient.buildIrohaClient()
        const result = await client.searchTransactionAsync(this.irohaRequestParam.get(shopCode,nptransactionId))
        return result[0].return
    } 

}
0 Answers
Related