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

Don't reconized import statement in with-jest-typescript example #5917

Closed
kkh975 opened this issue Dec 19, 2018 · 1 comment · Fixed by #5941
Closed

Don't reconized import statement in with-jest-typescript example #5917

kkh975 opened this issue Dec 19, 2018 · 1 comment · Fixed by #5941
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@kkh975
Copy link

kkh975 commented Dec 19, 2018

Examples bug report

I just added simple test file(not typescript file) in with-jest-typescript example.

import React from 'react';
import { shallow } from 'enzyme';

import Hello from './Hello';

describe('test', () => {
    it('should ', () => {
        const hello = shallow(<Hello />);
        expect(hello.text()).toEqual('Hello');
    });
});

and Hello.js file is

import React from 'react'

const Hello = () => <div>Hello</div>

export default Hello;

Example name

with-jest-typescript

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Open a project(example > with-jest-typescript)
  2. You make two files(Hello.js, Hello.test.js).
  3. Go to console. and "npm run test" or "yarn test"

Screenshots

2018-12-19 4 13 25

System information

  • OS: macOS
  • Version of Next.js: [e.g. 6.0.0]
@ztanner
Copy link
Member

ztanner commented Dec 23, 2018

I took a look into this. The issue you're experiencing is that jest.config.js is only configured to use babel-jest on *.tsx files. If you were to rename Hello.test.js to Hello.test.tsx it would work, but this is not ideal, since it's not a TypeScript component.

To support *.js extensions, you'd have to update your transform in jest.config.js to look something like:

  transform: {
    '^.+\\.(js|tsx)?$': 'babel-jest',
  },

You will probably run into an error with this due to mismatched versions of babel-jest and jest. If you update both of those to be the same version (in this case, ^23.6.0), your tests should pass.

I've submitted a PR to make sure those versions are in sync.

timneutkens pushed a commit that referenced this issue Dec 23, 2018
…#5941)

This fixes the `with-jest-typescript` example to keep jest in sync with babel-jest (also updated to the latest of both). Having them resolve to different versions was resulting in weird errors.

When attempting to update the `transform` property in `jest.setup.js` to add babel-jest support to *.js/jsx files, it would throw:

> Plugin 0 specified in "node_modules/next/babel.js" provided an invalid property of "default" (While processing preset: "node_modules/next/babel.js")

Indirectly, this will fix #5917, once the author updates `jest.setup.js` to have:
```js
  transform: {
    '^.+\\.(js|tsx)?$': 'babel-jest',
  },
```
@lock lock bot locked as resolved and limited conversation to collaborators Dec 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants