mercredi 18 décembre 2019

how to use jest.mock with params in callback

I have a problem with mock class with constructor. I try to do something like this.

/* global jest */

const mockAdworsUser = {
    method1: jest.fn(),
};

jest.mock('node-adwords', () => {
    return {
        AdwordsUser: mockAdworsUser
    };
});

import { AdsApi } from '../../../src/workers/google-shop-css-xml/google-ads-api';

describe('google-ads-api', () => {
    it('test', async () => {
        const adsApi = new AdsApi();

        adsApi.authorize();
    });
});

but I get an error like:

Test suite failed to run

ReferenceError: Cannot access 'mockAdworsUser' before initialization enter code here

Do you have any idea how can I fix it? I always write a test code like this, and it was fine.

Thanks

Aucun commentaire:

Enregistrer un commentaire