Coder Social home page Coder Social logo

Comments (13)

lelandrichardson avatar lelandrichardson commented on May 7, 2024

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.

geowarin avatar geowarin commented on May 7, 2024

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.

lelandrichardson avatar lelandrichardson commented on May 7, 2024

@geowarin ah. That trace is very helpful, thanks. I think we can get this fixed!

from enzyme.

lelandrichardson avatar lelandrichardson commented on May 7, 2024

Fixed in #53

from enzyme.

gabrielenosso avatar gabrielenosso commented on May 7, 2024

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.

ljharb avatar ljharb commented on May 7, 2024

@gabrielenosso SFCs must return something, they can't return null - can you share the code for your component?

from enzyme.

gabrielenosso avatar gabrielenosso commented on May 7, 2024

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.

gabrielenosso avatar gabrielenosso commented on May 7, 2024

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.

lelandrichardson avatar lelandrichardson commented on May 7, 2024

@gabrielenosso interesting. I'll give this a try today. This could be a bug with the way .text() is implemented.

from enzyme.

gabrielenosso avatar gabrielenosso commented on May 7, 2024

Thanks for your support! :)

from enzyme.

revolunet avatar revolunet commented on May 7, 2024

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.

griffinmichl avatar griffinmichl commented on May 7, 2024

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.

ffxsam avatar ffxsam commented on May 7, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.