I'm getting failed tests after installing an NPM package (one of my own packages).
Specifically, I'm getting ReferenceError: cc is not defined, with the stack trace leading back to one of the exports in my NPM package.
cc is an object from a game framework (Cocos2d-x) that is included in my project locally.
The game framework is not included in my NPM package, but the package does reference the object with the assumption that whatever project has the package installed will also have the game framework already included. So essentially, Cocos2d-x is a peer dependency, but is not listed as one since it's not an NPM package itself.
The code I'm testing in my project does not make any reference to the game framework. And the methods that I'm importing from my NPM package do not make any reference to the game framework. I'm importing these methods using destructuring (e.g. import { helper1 } from 'my-package').
With that said, I wouldn't expect it to be an issue. But Jest doesn't like the fact that cc is referenced from an entirely different export on my NPM package (one that is not being imported into the file being tested). In other words, helper2 is causing Jest to fail because it does reference cc, but helper2 isn't being imported.
How should I go about fixing this error so that the tests pass?
from Jest unit test failing with `ReferenceError` from NPM package module
No comments:
Post a Comment