Git Product home page Git Product logo

Comments (7)

stefcameron avatar stefcameron commented on June 17, 2024 1

i.e. module.exports = tabbable; instead of export default tabbable

Remember: Jest requires CJS. It doesn't natively understand ESM.

from tabbable.

stefcameron avatar stefcameron commented on June 17, 2024

@neeco90 Thanks for reaching out! Let's see if we can figure this out.

It looks like you correctly followed the Testing in JSDom topic in the README. If you hadn't, it wouldn't lead to this type of error. It would lead to errors like "your container must have at least one tabbable node in it"

This feels more like an issue with CJS require vs ESM import statements and the fact that Jest doesn't work with ESM. ES modules need to be transpiled to CJS to run under Jest, although tabbable provides both CJS and ESM bundles and, at least in my own projects that use it, doesn't typically have to be configured under Jest's transformIgnorePatterns option.

Sill, it feels like something related to this.

Maybe it's in the way you're importing (or requiring?) tabbable in your actual code since it seems to occur when you run what I'm guessing is RTL's render() function?

from tabbable.

nicolas-c-dev avatar nicolas-c-dev commented on June 17, 2024

Thanks for the quick answer! I'm just using the FocusTrap component in the modal, I'm not importing tabbable in any place.
image

I've tried changing the extension to .js but not recognizes jest. I'll keep investigating.

Thanks!

from tabbable.

nicolas-c-dev avatar nicolas-c-dev commented on June 17, 2024

I've find that the unrecognized jest error is just a misconfiguration for eslint, so it passes disabling eslint. But... now throws "unexpected token export" and can't get where is the error
image

from tabbable.

stefcameron avatar stefcameron commented on June 17, 2024

Try writing your tabbable mock module using CJS syntax instead of ESM. I think that will fix the issue.

from tabbable.

nicolas-c-dev avatar nicolas-c-dev commented on June 17, 2024

Thanks a lot @stefcameron ! u was right! I left the final code for others who find something similar
image

from tabbable.

stefcameron avatar stefcameron commented on June 17, 2024

You're welcome! I'm glad I could help! 🚀

from tabbable.

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.