Skip to content

fix: Determining inheritedMetadatas during jest+ts-jest tests collects metadatas that do not belong to the target #1810

@sdokara

Description

@sdokara

Description

This is a very edge-casey situation that I ran into.

I have a web service project in [email protected] on Node 16 with [email protected] classes being decorated. Everything runs perfectly in normal mode: tsc transpiles stuff and node runs it without issues. The validator collects the metadata properly.
But, when running tests with jest that uses ts-jest as the transformer (with default configuration), the transpiled output acts kinda weird.

For all decorated classes, in src/metadata/MetadataStorage.ts:109, when computing inheritedMetadatas, there's an if:

if (metadata.target instanceof Function && !(targetConstructor.prototype instanceof metadata.target))
    return false;

Now, during tests, metadata.target instanceof Function yields false even though it is the class and typeof metadata.target does indeed yield 'function'. I have no idea how this is happening. I'm able to monkey-patch it by using typeof.

This used to work with older versions of my dependencies, but I wasn't able to pinpoint the culprit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions