GithubHelp home page GithubHelp logo

[Bug]: Unexpected value 'Module' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation - while Module from library present in transformIgnorePatterns about jest-preset-angular HOT 15 OPEN

polonmedia avatar polonmedia commented on August 16, 2024
[Bug]: Unexpected value 'Module' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation - while Module from library present in transformIgnorePatterns

from jest-preset-angular.

Comments (15)

polonmedia avatar polonmedia commented on August 16, 2024

I tried this config
image
with this package.json ("@angular/core": "^13.0.0")
image
and still i have this shit
image
bro wtf, there is no winning, whatever I use in whatever sense - always an issue

from jest-preset-angular.

ahnpnl avatar ahnpnl commented on August 16, 2024

Did you check https://thymikee.github.io/jest-preset-angular/docs/guides/angular-13+?

from jest-preset-angular.

polonmedia avatar polonmedia commented on August 16, 2024

@ahnpnl yes, I did, I started with it, but there are always the same or similiar issues, mainly comming from node_modules

from jest-preset-angular.

ahnpnl avatar ahnpnl commented on August 16, 2024

The error I can see coming from a library you are using angular-support-bot, this would mean you need to tell Jest to transform the library files via transformIgnoredPatterns. That library has a folder node_modules which Jest complains about.

from jest-preset-angular.

polonmedia avatar polonmedia commented on August 16, 2024

No, this isnt a library, its an app that I try to use the jest in

from jest-preset-angular.

polonmedia avatar polonmedia commented on August 16, 2024

It isnt even clear from the link u sent - should I use the jest.config.ts from here
image
or from example?

from jest-preset-angular.

ahnpnl avatar ahnpnl commented on August 16, 2024

It isnt even clear from the link u sent - should I use the jest.config.ts from here image or from example?

This is the part if you want to use ESM mode (The title "Use ES modules" seems to be not clear enough)

In your case, js or ts config file isn't related. The problem is about Jest can't transform files from your node_modules for some reasons. The only way to fix is modifying transformIgnorePatterns.

If your project doesn't have any custom config on transforming files, perhaps you can compare your project config with example project https://github.com/thymikee/jest-preset-angular/blob/main/examples/example-app-v13/jest.config.js?

Another way is configuring moduleNameMapper to tell Jest where to load things.

from jest-preset-angular.

polonmedia avatar polonmedia commented on August 16, 2024

I also noticed that u enable this - skipNgcc: false,
but whenever I dont turn it to true, the following happens:
image
image

can it be somehow related?

I follow the exact config as u have in example for esm modules (npm run test-esm)

from jest-preset-angular.

polonmedia avatar polonmedia commented on August 16, 2024

If i skip it, following happens:
image

image
image
image
image
image

am i mentally challanged? something seems off whatever i try to do

from jest-preset-angular.

ahnpnl avatar ahnpnl commented on August 16, 2024

I'd recommend to keep skipNgcc: false, this ensures you are compatible with future Angular versions, in v16 they removed View Engine.

It's hard to check about this without a repo. Maybe you can somehow replicate the issue in the example-app-v13?

from jest-preset-angular.

polonmedia avatar polonmedia commented on August 16, 2024

@ahnpnl brother, i added this to the mjs config
image
image

but i get those errors now:
image
image
could u advise me to what direction should i look for?

from jest-preset-angular.

ahnpnl avatar ahnpnl commented on August 16, 2024

I can see that you are running Jest in ESM mode. The 2nd screenshot has a lib called cytiva-cui-design-ng and the js of this lib is loaded with umd. Maybe you can use moduleNameMapper to instruct Jest to load mjs file instead?

Moving to ESM mode is a very big thing btw. Normally I make CJS mode work first before trying out ESM mode.

from jest-preset-angular.

polonmedia avatar polonmedia commented on August 16, 2024

@ahnpnl thank u for your patience and responding to me, I managed to get past the config with your guidance and tests are almost working, I have one issue left to which I cannot comprehend and to which I cannot find a clear answer

I get this error while trying to use modules from my components library
image

This is how my library is in dist folder:
image

(I think it may be related) As I mentioned before, I have issue with running ngcc which produces following error
image

Could you perhaps point me to direction I should take to resolve this?

from jest-preset-angular.

polonmedia avatar polonmedia commented on August 16, 2024

I managed to tell ngcc to ignore the lib via this config:
image
But didnt resolve my issue

from jest-preset-angular.

polonmedia avatar polonmedia commented on August 16, 2024

Bumping to angular ver 14 didnt resolve nothing also

from jest-preset-angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.