Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sdokara opened this issue Nov 25, 2022 · 5 comments
Labels
status: invalid / expired Issues with no action to take. type: fix Issues describing a broken feature.

Comments

@sdokara
Copy link

sdokara commented Nov 25, 2022

Description

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

I have a web service project in typescript@4.9.3 on Node 16 with typeorm@0.2.32 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.

@sdokara sdokara added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Nov 25, 2022
@mzpeartx
Copy link

mzpeartx commented Dec 1, 2022

I am seeing a similar behavior. My current workaround was to downgrade to version 0.11.1.

@NoNameProvided
Copy link
Member

NoNameProvided commented Dec 2, 2022

I would guess this is due to a difference in how ts-jest compiles the code and you probably need to add some options to your test config.

I have some faded memories of someone having a similar issue quite some time ago, but there the problem was a change in babel transform that strips the metadata. Maybe you are affected by the same problem?

@mzpeartx
Copy link

mzpeartx commented Dec 2, 2022

@NoNameProvided That makes sense. I'll have to do a little digging, thanks for the suggestion!

@NoNameProvided NoNameProvided added status: invalid / expired Issues with no action to take. and removed status: needs triage Issues which needs to be reproduced to be verified report. labels Dec 9, 2022
@NoNameProvided
Copy link
Member

Closing this as invalid. I cannot provide support with general programming-related questions.

I hope you will find the bug.

@github-actions
Copy link

github-actions bot commented Jan 9, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: invalid / expired Issues with no action to take. type: fix Issues describing a broken feature.
Development

No branches or pull requests

3 participants