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

[Bug] URGENT TypeError: (0 , _umi.formatMessage) is not a function in JEST test framework #6528

Closed
tejparekh opened this issue May 7, 2021 · 6 comments

Comments

@tejparekh
Copy link

tejparekh commented May 7, 2021

I am trying to write the JEST test cases for my Component.

component.test.js
describe('CustomComponent tests cases', () => { it('should show the Add Button', () => { const wrapper = shallow(<CustomComponent />); const instance = wrapper.instance(); // expect(wrapper.state('visions')).arrayContaining([expect.objectContaining({Priority : '01'})]); instance.onSortEnd({oldIndex, newIndex}); expect(wrapper.find('Button')).toExist(); }); });

CustomComponent.js has the code where I am importing the UMI package
import { formatMessage, useIntl, FormattedMessage } from 'umi'

There is no issue in the UI the language file returns the string values.

When I am running the command npm test (jest and enzyme)
I am thrown the error the as following

formatMessageError

Package Json
"dependencies": { "@ant-design/icons": "^4.0.0", "@ant-design/pro-descriptions": "^1.2.0", "@ant-design/pro-form": "^1.3.0", "@ant-design/pro-layout": "^6.16.1", "@ant-design/pro-table": "^2.17.0", "@umijs/route-utils": "^1.0.33", "antd": "^4.12.0", "array-move": "^3.0.1", "react": "^16.14.0", "react-dev-inspector": "^1.1.1", "react-dom": "^17.0.0", "react-helmet-async": "^1.0.4", "react-sortable-hoc": "^2.0.0", "umi": "^3.4.1", "umi-request": "^1.0.8" }, "devDependencies": { "@ant-design/pro-cli": "^1.0.28", "@types/classnames": "^2.2.7", "@types/express": "^4.17.0", "@types/history": "^4.7.2", "@types/lodash": "^4.14.144", "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", "@types/react-helmet": "^6.1.0", "@umijs/fabric": "^2.5.1", "@umijs/plugin-blocks": "^2.0.5", "@umijs/plugin-esbuild": "^1.0.1", "@umijs/preset-ant-design-pro": "^1.2.0", "@umijs/preset-react": "^1.4.8", "@umijs/yorkie": "^2.0.3", "carlo": "^0.9.46", "chalk": "^4.0.0", "cross-env": "^7.0.0", "cross-port-killer": "^1.1.1", "detect-installer": "^1.0.1", "enzyme": "^3.11.0", "enzyme-adapter-react-16": "^1.15.6", "eslint": "^7.1.0", "express": "^4.17.1", "gh-pages": "^3.0.0", "jest": "^26.6.3", "jest-environment-enzyme": "^7.1.2", "jest-enzyme": "^7.1.2", "jsdom-global": "^3.0.2", "lint-staged": "^10.0.0", "mockjs": "^1.0.1-beta3", "nyc": "^15.1.0", "prettier": "^2.0.1", "puppeteer-core": "^8.0.0", "react-addons-test-utils": "^15.6.2", "stylelint": "^13.0.0", "typescript": "^4.0.3" },

Thanks for your help

@tejparekh tejparekh changed the title [Bug] TypeError: (0 , _umi.formatMessage) is not a function [Bug] URGENT TypeError: (0 , _umi.formatMessage) is not a function in JEST test framework May 7, 2021
@xiaohuoni
Copy link
Member

疑似相同问题#5138

@sonce
Copy link

sonce commented May 15, 2021

TypeError: umi_1.request is not a function

解决了吗?我也遇到类似这个问题。

@tejparekh
Copy link
Author

tejparekh commented May 15, 2021 via email

@sajjadshahi
Copy link

@xiaohuoni Yeah it exactly is the same problem. I think the main problem is that the plugins are built runtime and are not accessible directly from umi node_modules directory.

@xiaohuoni
Copy link
Member

我觉得这个方法能够解决问题 #5138 (comment)

@httol
Copy link

httol commented Mar 17, 2022

我觉得这个方法能够解决问题 #5138 (comment)

不可以

@sorrycc sorrycc closed this as completed Jul 4, 2022
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

6 participants