Comments (9)
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.
@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.
@markalfred Worked great when importing as one of the first packages. Thanks!
from react-generate-props.
👍 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.
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.
This is broken for me as well. I tried the suggestion of changing the order of import to no avail.
Its failing on any shape() PropType.
from react-generate-props.
@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.
@markalfred updated my comment.
from react-generate-props.
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)
- Generate reasonable values for all simple types
- Generate reasonable values for all complex types
- Maybe generate values for non-required props
- Take generator overrides
- Support older node versions
- Handle defaultProps
- Support React 15.5 and above
- Allow for deterministic tests
- Use reducer initialState to generate props HOT 5
- { optional: true } doesn't generate deeply-nested optional props in shapes HOT 1
- generateProps should be able to take a PropType as its argument
- Return more information in generator callbacks HOT 2
- High order component HOT 2
- Generators could receive prop name as argument HOT 6
- Add PropType.symbol support HOT 1
- Allow for Generation of Custom Prop Types HOT 3
- Generate PropTypes.exact
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-generate-props.