GithubHelp home page GithubHelp logo

Comments (9)

markalfred avatar markalfred commented on May 28, 2024 1

Just to give an update: I've been thinking about and experimenting with solutions for this, but the only viable option I can come up with is: throw an error if a PropTypes.(anything) has been called before this library had a chance to wrap PropTypes correctly. This feels like a bit of a cop-out, but it will at least make it clear that this was the problem. I haven't been able to come up with any way to backfill previously-defined propTypes, and I haven't been able to reproduce this issue in any other ways, so this might be what we're stuck with. But I'll keep thinking about this and update if I have anything else. Sorry for the delay in getting this completely resolved.

from react-generate-props.

markalfred avatar markalfred commented on May 28, 2024

@mcpants I just ran into this yesterday... Are you require-ing or import-ing your component before requiring this lib?

Try switching the import order, or just calling require('react-generate-props') one time at the very start of your test suite, and let me know if that fixes it.

If that works, great, but it's totally undocumented and I'd like to either document this gotcha or come up with a better solution. Sorry for the hassle!

from react-generate-props.

AshesOfOwls avatar AshesOfOwls commented on May 28, 2024

@markalfred Worked great when importing as one of the first packages. Thanks!

from react-generate-props.

markalfred avatar markalfred commented on May 28, 2024

👍 Good to hear @mcpants — I'm going to keep this open in case others run into it, and to ensure I come up with a better solution 😂

from react-generate-props.

Duskfall avatar Duskfall commented on May 28, 2024

Doesn't work for me :/

component.js:
Component.propTypes = {
groups: PropTypes.arrayOf(PropTypes.shape({
    id: PropTypes.number.isRequired,
  })),
}

test.js:
import React from 'react';
import { shallow } from 'enzyme';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

import Component from './component';
import generateProps from 'react-generate-props'

Enzyme.configure({ adapter: new Adapter() });

let foo =  generateProps(Component)

the type in line: var generate = options.generators[propType.type]; is undefined

I have also tried with require and changing the order, but nothing worked for me.

prop-types version: 15.6.0

from react-generate-props.

aaroncouture avatar aaroncouture commented on May 28, 2024

This is broken for me as well. I tried the suggestion of changing the order of import to no avail.
screen shot 2018-01-25 at 11 23 36 am

Its failing on any shape() PropType.

screen shot 2018-01-25 at 11 26 07 am

from react-generate-props.

markalfred avatar markalfred commented on May 28, 2024

@Duskfall since the groups prop isn't required, it won't be generated by default. As of the current version, optional props aren't generated by default. Could you try passing the { optional: true } opt to generateProps?

let foo =  generateProps(Component, { optional: true })

[docs]

from react-generate-props.

aaroncouture avatar aaroncouture commented on May 28, 2024

@markalfred updated my comment.

from react-generate-props.

AshCoolman avatar AshCoolman commented on May 28, 2024

the type in line: var generate = options.generators[propType.type]; is undefined

@Duskfall Ah yes, the latest commit seems to grief me in the same way

$ node --version
v9.2.0
$ yarn --version
1.3.2
$ rm -r node_modules/; yarn; yarn react:16; yarn build; yarn link;

Gives me this error

index.js:16 TypeError: Cannot read property 'bind' of undefined
    at generateOneProp (VM507 preview.bundle.js:59246)
    at VM507 preview.bundle.js:102927
    at VM507 preview.bundle.js:104289
    at baseForOwn (VM507 preview.bundle.js:102374)
    at VM507 preview.bundle.js:104258
    at baseMap (VM507 preview.bundle.js:102926)
    at Function.map (VM507 preview.bundle.js:108918)
    at interceptor (VM507 preview.bundle.js:116355)
    at Function.thru (VM507 preview.bundle.js:108159)
    at VM507 preview.bundle.js:103752

Note: 0.3.0 works fine for me

from react-generate-props.

Related Issues (18)

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.