Comments (13)
Agreed this should definitely work out of the box. Thank you for the suggested workaround... I'm a bit surprised that this doesn't "just work" and would like to do a bit more research regarding what the "right" way to get this working with reagent would be.
Do you know if shallow
works with stateless components?
from enzyme.
Yes, it does work with shallow()
.
Stacktrace with mount:
TypeError: Cannot read property '_reactInternalComponent' of null
at internalInstanceOrComponent (/Users/geowarin/dev/2015/spring/new/boot-react/frontend/node_modules/reagent/build/MountedTraversal.js:135:18)
at treeFilter (/Users/geowarin/dev/2015/spring/new/boot-react/frontend/node_modules/reagent/build/MountedTraversal.js:261:40)
at ReactWrapper.<anonymous> (/Users/geowarin/dev/2015/spring/new/boot-react/frontend/node_modules/reagent/build/ReactWrapper.js:37:45)
at /Users/geowarin/dev/2015/spring/new/boot-react/frontend/node_modules/reagent/build/ReactWrapper.js:617:19
at Array.map (native)
at ReactWrapper.flatMap (/Users/geowarin/dev/2015/spring/new/boot-react/frontend/node_modules/reagent/build/ReactWrapper.js:616:30)
at findWhereUnwrapped (/Users/geowarin/dev/2015/spring/new/boot-react/frontend/node_modules/reagent/build/ReactWrapper.js:36:18)
at ReactWrapper.find (/Users/geowarin/dev/2015/spring/new/boot-react/frontend/node_modules/reagent/build/ReactWrapper.js:224:14)
at Context.<anonymous> (/Users/geowarin/dev/2015/spring/new/boot-react/frontend/test/components/MyComponent.spec.js:25:17)
from enzyme.
@geowarin ah. That trace is very helpful, thanks. I think we can get this fixed!
from enzyme.
Fixed in #53
from enzyme.
I have a problem with that: using mount with a stateless component I get:
Invariant Violation: Element appears to be neither ReactComponent nor DOMNode (keys: _currentElement,_rootNodeID,_instance,_pendingElement,_pendingStateQueue,_pendingReplaceState,_pendingForceUpdate,_renderedComponent,_context,_mountOrder,_topLevelWrapper,_pendingCallbacks,_mountIndex,_mountImage,_isOwnerNecessary,_warnedAboutRefsInRender)
from enzyme.
@gabrielenosso SFCs must return something, they can't return null
- can you share the code for your component?
from enzyme.
I know that they can't return null, so it isn't the problem.
I will try to share some code tomorrow morning.
Thank you for your help!
from enzyme.
It gives me the problem when I use the .text() method.
const Button = (props) => (
<div>
</div>
);
export default Button;
import React from 'react';
import { mount } from 'enzyme';
import { expect } from 'chai';
import Button from './Button';
describe('Button', () => {
it('should render its label', () => {
const labelValue = 'labelValue';
expect(mount(<Button label={labelValue} />).text().indexOf(labelValue) >= 0).to.be.true;
});
});
from enzyme.
@gabrielenosso interesting. I'll give this a try today. This could be a bug with the way .text()
is implemented.
from enzyme.
Thanks for your support! :)
from enzyme.
Using 2.1.0 and looks like functionnal components dont work, or i dont use it correctly ?
export const Test = () => <div>Test</div>;
let w = mount(<Test/>);
console.log(w.debug());
this outputs nothing... normal ?
from enzyme.
I am currently working on #261, and I have encountered a similar issue. Calling .text() directly on the wrapper does not work for stateless function components. I believe the issue can be traced to the use of findDOMNode. More information can be found here: facebook/react#4936.
from enzyme.
I found this issue because I was having problems with testing stateless functions as well:
/Users/samh/test/client/components/Thing.js:13
exports["default"] = Thing = function Thing() {
^
ReferenceError: Thing is not defined
I just wanted to follow the progress on this.
from enzyme.
Related Issues (20)
- enzyme-adapter-react-18 HOT 2
- Component is not re-rendered with updated states HOT 5
- Cheerio 1.0.0-rc.11 no longer support deep imports HOT 3
- enzyme crash since Cheerio 1.0.0-rc.11 release HOT 5
- CSS selectors match component props rather than rendered DOM HOT 6
- Cannot read property 'child' of undefined on React 16 + enzyme-adapter-react-16 HOT 1
- Cannot read property 'child' of undefined enzyme-adapter-react-16 and react 17.0.2 HOT 3
- "TypeError: Cannot read properties of undefined (reading 'current')" in mount API HOT 7
- Method βpropsβ is only meant to be run on a single node. 0 found instead. HOT 1
- How to test the form which is rendered based on props in class component in react.js ? HOT 3
- How to test the state values which are setting the state from local storage inside componentDidMount in enzyme using reactjs ? HOT 5
- Function `mount` does not mock proper data HOT 5
- [email protected] does not include latest changes as per master HOT 5
- Document `getElement(s)` for full DOM rendering HOT 3
- TypeError: window.require is not a function HOT 5
- Does Enzyme support React 18.0.2 ? HOT 1
- Is this library 'dead'? HOT 5
- Explain how the synchronization works HOT 1
- Mount and simulate are failing after changing to Node 16 HOT 10
- enzyme-adapter-react-18 HOT 1
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 enzyme.