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

Broken React example #88

Closed
popham opened this issue Jul 14, 2014 · 8 comments
Closed

Broken React example #88

popham opened this issue Jul 14, 2014 · 8 comments

Comments

@popham
Copy link

popham commented Jul 14, 2014

Here's my initialization sequence: git clone https://github.com/facebook/jest.git && cd jest && npm install && npm install react && npm install react-tools && cd examples/react && node ../../bin/jest.js. I get the following error:

TypeError: .../jest/node_modules/react/addons.js:
.../jest/node_modules/react/lib/ReactWithAddons.js:
.../jest/node_modules/react/lib/React.js:
.../jest/node_modules/react/lib/ReactCompositeComponent.js:
Cannot read property 'DEFINE_MANY' of undefined
@sophiebits
Copy link
Contributor

If you run npm install inside the examples/react directory, then react and react-tools will be installed there, causing them to be properly unmocked from the path specified in examples/react/package.json; you'll get this output:

jest/examples/react$ npm test

> node ../../bin/jest.js

Using Jest CLI v0.1.17
Found 1 matching test...
 PASS  __tests__/CheckboxWithLabel-test.js (1.9s)
1 test passed (1 total)
Run time: 3.029s

@revskill10
Copy link

Hi, i'm facing similar issue when testing React.
My folder structure:

app/
     /__tests__/
                    /CheckboxWithLabel-test.js
    /CheckboxWithLabel.js
    /package.json
    /preprocessor.js

I use Windows. Other test types work fine. But when running on windows: npm test, the output is a type error with output likes that:

- TypeError: D:\code\js\flux\node_modules\react\addons.js:
D:\code\js\flux\node_modules\react\lib\React.js:
D:\code\js\flux\node_modules\react\lib\ReactWithAddons.js
D:\code\js\flux\node_modules\react\lib\ReactCompositeComponent.js: Cannot read property 'DEFINE_MANY' of undefined

Could you help me figure out the issue here ?

@popham
Copy link
Author

popham commented Jul 19, 2014

Look in the example's package.json versus the root package.json. Specifically,

"unmockedModulePathPatterns": ["<rootDir>/node_modules/react"]

React will not tolerate any mockery. I was embarrassed to find it in the docs a couple minutes after my post and the quick response. (Thanks for not calling me out @spicyj).

@revskill10
Copy link

Thank you for so quick reply.
I'm sorry because i don't understand the rootDir here.
In my case, i have my app directory (flux in this case). My package.json is:
{
"name": "flux",
"version": "0.0.0",
"description": "",
"author": "",
"license": "ISC",
"devDependencies": {
"envify": "^1.2.1",
"es6-promise": "1.0.0",
"gulp": "^3.7.0",
"gulp-browserify": "^0.5.0",
"gulp-concat": "^2.2.0",
"jest-cli": "^0.1.17",
"jquery": "^2.1.1",
"jsdom": "^0.11.1",
"mocha": "^1.20.1",
"react": "^0.10.0",
"react-tools": "^0.11.0",
"reactify": "^0.13.1",
"sinon": "^1.10.3"
},
"scripts": {
"test": "node node_modules/jest-cli/bin/jest.js"
},
"jest": {
"scriptPreprocessor": "D:/code/js/flux/preprocessor.js",
"unmockedModulePathPatterns": ["D:/code/js/flux/node_modules/react"]
}
}

or, i use the instead of absolute path , but the error is the same. Is it Windows error specific ?

@popham
Copy link
Author

popham commented Jul 20, 2014

Can you push your code to github?

@revskill10
Copy link

Hi, my code is here: https://github.com/checkraiser/testjest

@popham
Copy link
Author

popham commented Jul 20, 2014

Running

git clone https://github.com/checkraiser/testjest
cd testjest
npm install
npm install jest-cli
./node_modules/.bin/jest

I get

Found 1 matching tests...
PASS  __tests__/CheckboxWithLabel-test.js (8.417s)
1 tests passed (1 total)
Run time: 14.426s

uname -a gives me Linux Device-63FD55 3.15.1-1-ARCH #1 SMP PREEMPT Tue Jun 17 09:32:20 CEST 2014 x86_64 GNU/Linux (64-bit Archlinux). Looks Windows specific, but I don't have a Windows box to verify. Sounds like this warrants a new issue.

@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

3 participants