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

Cannot test component wrapped with ConfigProvider #26985

Closed
1 task done
JesusTheHun opened this issue Oct 1, 2020 · 9 comments
Closed
1 task done

Cannot test component wrapped with ConfigProvider #26985

JesusTheHun opened this issue Oct 1, 2020 · 9 comments

Comments

@JesusTheHun
Copy link
Contributor

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

https://github.com/JesusTheHun/antd-cra-rtl-error

Steps to reproduce

yarn test

What is expected?

The test should pass

What is actually happening?

The test fails to start with the error :

path/node_modules/antd/es/locale/en_US.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import defaultLocale from './default';
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      2 | import logo from './logo.svg';
      3 | import './App.css';
    > 4 | import antdLocaleEnUS from 'antd/es/locale/en_US';
        | ^
      5 | import {ConfigProvider} from "antd";
      6 | 
      7 | function App() {

      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
      at Object.<anonymous> (src/App.tsx:4:1)
Environment Info
antd 4.6.6
React 16.13.1
System MacOS 10.15.7
Browser node
@JesusTheHun
Copy link
Contributor Author

The same issue occurs with Tooltip that imports Affix.

export { default as Affix } from './affix';
^^^^^^

SyntaxError: Unexpected token 'export'
import { Tooltip } from 'antd/es';

@afc163
Copy link
Member

afc163 commented Oct 2, 2020

@afc163 afc163 closed this as completed Oct 2, 2020
@JesusTheHun
Copy link
Contributor Author

You understand that this kind of arrogant response contribute to your horrible reputation as a dev team, right ?
I'm dead serious, instead of providing useful information you point me to google.
Do you understand how that makes you look like ? Look around, you are about to become a meme for arrogant dev.

@JesusTheHun
Copy link
Contributor Author

For anyone running into this issue, add the following to your package.json :

  "jest": {
    "transformIgnorePatterns": [
      "/node_modules/(?!antd|rc-.+?|@babel/runtime|@ant-design).+(js|jsx)$"
    ]
  }

@afc163
Copy link
Member

afc163 commented Oct 2, 2020

It is not a antd issue but jest usage, I am glad that you find solution and share it.

@afc163
Copy link
Member

afc163 commented Oct 2, 2020

I just found another workaround:

- import antdLocaleEnUS from 'antd/es/locale/en_US';
+ import antdLocaleEnUS from 'antd/lib/locale/en_US';

@afc163
Copy link
Member

afc163 commented Oct 2, 2020

@JesusTheHun
Copy link
Contributor Author

I've submitted a PR to improve the documentation regarding this issue. I believe it will improve the developer experience with Ant Design.

#27003

@OpenSourceLucy
Copy link

It works for antd if we use antd/lib/ instead of antd/es/
So I solved the problem adding "moduleNameMapper" in the package.json.

"jest": {
  "moduleNameMapper": {
    "^antd/es/": "antd/lib/"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants