0

I would like to extend jest namespace declared globally by adding a new custom spy-like function. The declaration seems to be accepted by the compiler but at run-time I am getting TypeError: jest.spyOnDispatchedActions is not a function

// jest-helpers.ts

declare global {
    namespace jest {
        function spyOnSomething(args...): SomeType;
    }
}

export namespace jest {
    export function spyOnSomething(args...): SomeType {
        ...
    };
}
export { };

In my spec-file I am calling the new function like this:

// something.spec.ts
    it('...', () => {
        const val = jest.spyOnSomething(...);
        ...
    });

jest-helpers.ts is imported in setupJest.ts:

import '~/testing/utils/jest-helpers';

What am I doing wrong?

0 Answers0