Skip to content

Jest service mocks have wrong types #614

@DaSchTour

Description

@DaSchTour

Discussed in #613

Originally posted by DaSchTour June 1, 2023
I have some code that uses mocks and jest functions like mockReturnValue. For example like this

const fooService = spectator.inject(FooService);
fooService.someMethod.mockReturnValue({foo: 'bar'});

This worked fine but now suddenly I get typescript errors TS2339: Property 'mockReturnValue' does not exist on type '((key: string | null, location?: string | undefined) => Observable ) & CompatibleSpy'..

It looks like typescript doesn't use the jest typings but the jasmine version.

I'm not sure if that is an issue with my configuration, with a wrong version of jest or maybe caused by TypeScript 5. Did anybody else expect similar issues?

This issue is also present in https://github.com/ngneat/spectator/blob/master/projects/spectator/jest/test/auth.service.spec.ts

So probably there is something wrong with the jest SpyObject typings.

Interesting is, that when opening the file in VSCode or IntelliJ there are errors shown, but the test run correctly without issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions