
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
An experiment in automatically generating sets of supposedly-valid props for React components, in order to make tests write themselves.
An experiment in automatically generating sets of supposedly-valid props for React components, in order to make tests write themselves.
This is experimental at best. React's maintainers are moving toward favoring Flow type-checking over propTypes. The algorithm for generating test props is quite slow. It's also pretty stupid and won't create much variation, which has both advantages and disadvantages.
That all said, except for slowing down your test suite, any shortcomings are mostly harmless.
It's a very simple, brute-force technique, like fuzzing is.
You can then use those props objects to render the component and answer the question:
"If I obey my PropTypes validation rules, does the component render without exploding?"
If your components explodes when given supposedly-valid props, you should consider either handling the input that made it explode or tightening its propTypes validation.
Mocha/enzyme/ES6 example:
import React, {Component, PropTypes, createElement} from 'react'
import {mount} from 'enzyme'
import fuzzProps from 'fuzzprops'
class Numbers extends Component {
static propsTypes = {
optionalNumber: PropTypes.number,
requiredNumber: PropTypes.number.isRequired,
};
render() {
return <div />
}
}
const fuzzerValues = [
'Hello, World!',
null,
undefined,
-1,
0,
1,
1234.4321,
'1',
'-1',
'0',
'1234.4321',
{},
[],
[0],
[0,0,0,0,0,0,0,0],
['1234', 2134, 'safasfa', null],
]
const maxIterations = 10
describe('Numbers component', function() {
it('should render without throwing when given valid props', function() {
fuzzProps(Numbers, fuzzerValues, maxIterations).forEach(function(props) {
mount(<Numbers ...props>{props.children || null}</Numbers>)
})
})
})
FAQs
An experiment in automatically generating sets of supposedly-valid props for React components, in order to make tests write themselves.
The npm package fuzzprops receives a total of 1 weekly downloads. As such, fuzzprops popularity was classified as not popular.
We found that fuzzprops demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.