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

[docs] ES6 Import patterns and relative paths #972

Closed
andrewmclagan opened this issue May 6, 2016 · 4 comments
Closed

[docs] ES6 Import patterns and relative paths #972

andrewmclagan opened this issue May 6, 2016 · 4 comments

Comments

@andrewmclagan
Copy link

andrewmclagan commented May 6, 2016

This is most likely not and issue and just needs more documentation?

I list my components under relative paths such as: src/components/index.js with NODE_ENV=./src making the following possible: import { MyComponent } from 'components';

When the component under test includes another sub-component from index.js Jest throws various errors as it steps into the index.js file and picks up ALL my components.

jest.unmock('../MyComponent'); //

import { MyComponent } from '../MyComponent';

// ... tests below ...

Where MyComponent imports a sub-component as such:

// file: `MyComponent`

import 'SubComponent' from 'components';

// ... component code below

Is there a way to get around this situation where Jest tries to import ALL the components in an index file rather then just what is needed for the test purpose?

@andrewmclagan
Copy link
Author

andrewmclagan commented May 6, 2016

could be related to #973 and default exports? reopening this issue as there seems allot of confusion around es6 imports/exports and how babel-jest is interpreting them?

@andrewmclagan andrewmclagan reopened this May 6, 2016
@cpojer
Copy link
Member

cpojer commented May 6, 2016 via email

@cpojer
Copy link
Member

cpojer commented May 10, 2016

I don't understand how you are using the NODE_ENV variable. It is supposed to contain values like production or dev or test. Jest actually sets it if it isn't explicitly specified and it is what makes unmock work together with import. If you set it to a path, it will not work properly with Jest.

If this turns out to be a Jest issue after fixing your setup, please provide a repository that shows this issue and I will reopen and fix this bug.

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants