Comments (9)
I am experiencing the same error, @michaelsync did you ever figure it out? CC: @jamesbrauman
from react-slider.
I think I got this error because of "ref". If I temporarily removed the code related to refs (e.g. ref: 'slider', ref: 'bar' + i, ref: 'handle' + i, var slider = this.refs.slider;
), I no longer get this error anymore.
I am very new to React so feel free to let me know if I am missing something here.. If it's an known issue, I would like to know when we can get the fix.
from react-slider.
Thank for the report. Could you please post some minimal amount of code that reproduces the issue?
from react-slider.
@jamesbrauman Sorry. I didn't get the notification.
Here is some repo.
Here is the list of files that I have.
Package.json
{
"name": "ms-jest-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"author": "ms",
"license": "ISC",
"dependencies": {
"react": "15.3.0",
"react-addons-test-utils": "^15.3.0",
"react-dom": "15.3.0",
"react-slider": "^0.7.0"
},
"devDependencies": {
"babel-jest": "^14.1.0",
"babel-polyfill": "^6.9.1",
"babel-preset-es2015": "",
"babel-preset-react": "",
"jest-cli": "^14.1.0",
"react-addons-test-utils": "~15.3.0"
},
"jest": {
"unmockedModulePathPatterns": [
"/node_modules/react/",
"/node_modules/react-dom/",
"/node_modules/react-addons-test-utils/"
]
}
}
MyCoolComponent.react
var React = require('react');
var ReactSlider = require('react-slider');
var MyCoolComponent = React.createClass({
render: function() {
return(
<div>
<ReactSlider defaultValue={50} />
</div>
);
}
});
module.exports = MyCoolComponent;
MyCoolComponent-Spec.js
jest.unmock('../MyCoolComponent.react')
.unmock('react-slider'); // unmock to use the actual implementation of sum
describe('when the page is loaded', () => {
var React = require('react'),
ReactDOM = require('react-dom');
var TestUtils = require('react-addons-test-utils');
var page;
beforeEach(function () {
var myComponent = require('../MyCoolComponent.react');
page = TestUtils.renderIntoDocument(React.createElement(myComponent));
var a = 1;
});
it('some HTML elements should be there.', () => {
expect(1).toBe(1);
});
it('some CSS elements should be there.', () => {
expect(1).toBe(1);
});
});
Error
No results
DEBUG CONSOLE
- Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's
render
method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).
at invariant (node_modules\fbjs\lib\invariant.js:38:15)
at Object..ReactOwner.addComponentAsRefTo (node_modules\react\lib\ReactOwner.js:69:79)
at attachRef (node_modules\react\lib\ReactRef.js:23:16)
at Object..ReactRef.attachRefs (node_modules\react\lib\ReactRef.js:42:5)
at ReactDOMComponent.attachRefs (node_modules\react\lib\ReactReconciler.js:24:12)
at CallbackQueue.Object.._assign.notifyAll (node_modules\react\lib\CallbackQueue.js:67:22)
at ReactReconcileTransaction.Object..ON_DOM_READY_QUEUEING.close (node_modules\react\lib\ReactReconcileTransaction.js:81:26)
at ReactReconcileTransaction.Object..Mixin.closeAll (node_modules\react\lib\Transaction.js:204:25)
at ReactReconcileTransaction.Object..Mixin.perform (node_modules\react\lib\Transaction.js:151:16)
at batchedMountComponentIntoNode (node_modules\react\lib\ReactMount.js:126:15)
at ReactDefaultBatchingStrategyTransaction.Object..Mixin.perform (node_modules\react\lib\Transaction.js:138:20)
at Object..ReactDefaultBatchingStrategy.batchedUpdates (node_modules\react\lib\ReactDefaultBatchingStrategy.js:63:19)
at Object.batchedUpdates (node_modules\react\lib\ReactUpdates.js:98:20)
at Object..ReactMount._renderNewRootComponent (node_modules\react\lib\ReactMount.js:285:18)
at Object..ReactMount._renderSubtreeIntoContainer (node_modules\react\lib\ReactMount.js:371:32)
at Object..ReactMount.render (node_modules\react\lib\ReactMount.js:392:23)
at Object..ReactTestUtils.renderIntoDocument (node_modules\react\lib\ReactTestUtils.js:85:21)
at Object. (tests\MyCoolComponent-Spec.js:12:22)
● when the page is loaded › it some CSS elements should be there. - Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's
render
method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).
at invariant (node_modules\fbjs\lib\invariant.js:38:15)
at Object..ReactOwner.addComponentAsRefTo (node_modules\react\lib\ReactOwner.js:69:79)
at attachRef (node_modules\react\lib\ReactRef.js:23:16)
at Object..ReactRef.attachRefs (node_modules\react\lib\ReactRef.js:42:5)
at ReactDOMComponent.attachRefs (node_modules\react\lib\ReactReconciler.js:24:12)
at CallbackQueue.Object.._assign.notifyAll (node_modules\react\lib\CallbackQueue.js:67:22)
at ReactReconcileTransaction.Object..ON_DOM_READY_QUEUEING.close (node_modules\react\lib\ReactReconcileTransaction.js:81:26)
at ReactReconcileTransaction.Object..Mixin.closeAll (node_modules\react\lib\Transaction.js:204:25)
at ReactReconcileTransaction.Object..Mixin.perform (node_modules\react\lib\Transaction.js:151:16)
at batchedMountComponentIntoNode (node_modules\react\lib\ReactMount.js:126:15)
at ReactDefaultBatchingStrategyTransaction.Object..Mixin.perform (node_modules\react\lib\Transaction.js:138:20)
at Object..ReactDefaultBatchingStrategy.batchedUpdates (node_modules\react\lib\ReactDefaultBatchingStrategy.js:63:19)
at Object.batchedUpdates (node_modules\react\lib\ReactUpdates.js:98:20)
at Object..ReactMount._renderNewRootComponent (node_modules\react\lib\ReactMount.js:285:18)
at Object..ReactMount._renderSubtreeIntoContainer (node_modules\react\lib\ReactMount.js:371:32)
at Object..ReactMount.render (node_modules\react\lib\ReactMount.js:392:23)
at Object..ReactTestUtils.renderIntoDocument (node_modules\react\lib\ReactTestUtils.js:85:21)
at Object. (tests\MyCoolComponent-Spec.js:12:22)
2 tests failed, 0 tests passed (2 total in 1 test suite, run time 3.295s)
from react-slider.
If I remove ".unmock('react-slider')" to automock the slider then it works. But I don't want to auto-mock the slider and I want to test the DOM.
from react-slider.
Thanks for providing that example - I'll take a look into this.
from react-slider.
Hi @jamesbrauman Did you manage to replicate the issue?
from react-slider.
@michaelsync Sorry I have not yet had a chance to investigate the issue. If you would like to and create a pull request that fixes the bug, it would be appreciated, otherwise I'll get to it when I have a chance.
from react-slider.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from react-slider.
Related Issues (20)
- React 18.3: A props object containing a "key" prop is being spread into JSX HOT 4
- First click on track doesn't work when slider value is array and array values is equal
- Typescript issue HOT 1
- Possible to use a gradient as background for the slider? HOT 1
- Feature request: provide a way of detecting when react-slider has/loses focus HOT 2
- The specified value "1,669" cannot be parsed, or is out of range. HOT 1
- disabled does not apply to child elements?
- [TypeScript] `renderThumb`
- Module not found: Error: Can't resolve '@babel/runtime/helpers/inheritsLoose' HOT 4
- How to handle key events when I have global listeners? HOT 2
- Thumb Incorrect positioning HOT 1
- Slider not changing value when running Cypress tests HOT 3
- Wrong index in change event when changing thumb value through click
- No option to remove the slider thumb from the 'tab flow' HOT 1
- README.md file should be updated for how to use the packege HOT 2
- Missing dependency: @babel/runtime HOT 1
- Styling instructions are out of date
- Not working on Scaled Div
- Possible Incorrect State Management
- Incompatibility with React Testing Library
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-slider.