react-moment-proptypes
Advanced tools
Comparing version 1.3.0 to 1.4.0
{ | ||
"name": "react-moment-proptypes", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "React proptype for moment module", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -16,2 +16,8 @@ var moment = require('moment'); | ||
function createInvalidRequiredErrorMessage(propName, componentName, value) { | ||
return new Error( | ||
'The prop `' + propName + '` is marked as required in `' + componentName + '`, but its value is `' + value + '`.' | ||
); | ||
} | ||
function createMomentChecker(type, typeValidator, validator, momentType) { | ||
@@ -28,19 +34,19 @@ | ||
) { | ||
var propValue = props[ propName ]; | ||
var propType = typeof propValue; | ||
var isPropValueUndefined = typeof propValue === 'undefined'; | ||
var isPropValueNull = propValue === null; | ||
if (isRequired) { | ||
var locationName = ReactPropTypeLocationNames[ location ]; | ||
componentName = componentName || ANONYMOUS; | ||
propFullName = propFullName || propName; | ||
if (!props.hasOwnProperty(propName)) { | ||
return new Error( | ||
'Required ' + locationName + ' `' + propFullName + | ||
'` was not specified in `' + | ||
componentName + '`.' | ||
); | ||
if (isPropValueUndefined) { | ||
return createInvalidRequiredErrorMessage(propFullName, componentName, 'undefined'); | ||
} else if (isPropValueNull) { | ||
return createInvalidRequiredErrorMessage(propFullName, componentName, 'null'); | ||
} | ||
} | ||
var propValue = props[ propName ]; | ||
var propType = typeof propValue; | ||
if (typeof propValue === 'undefined' || propValue === null) { | ||
if (isPropValueUndefined || isPropValueNull) { | ||
return null; | ||
@@ -47,0 +53,0 @@ } |
123
test/test.js
@@ -77,3 +77,3 @@ import React from 'react'; | ||
expect(warnings.length).to.equal(1); | ||
expect(warnings[0]).to.contain('Required prop'); | ||
expect(warnings[0]).to.contain('required'); | ||
done(); | ||
@@ -85,2 +85,61 @@ | ||
describe('null required object', () => { | ||
before(() => { | ||
TestClass = React.createClass({ | ||
propTypes : { | ||
testRequiredObject : MomentPropTypes.momentObj.isRequired, | ||
}, | ||
render() { | ||
return null; | ||
}, | ||
}); | ||
}); | ||
it('should have a warning for the null moment obj', (done) => { | ||
const testElement = <TestClass testRequiredObject={null}/>; | ||
TestUtils.renderIntoDocument(testElement); | ||
expect(warnings).to.be.an('array'); | ||
expect(warnings.length).to.equal(1); | ||
expect(warnings[0]).to.contain('required'); | ||
expect(warnings[0]).to.contain('null'); | ||
done(); | ||
}); | ||
}); | ||
// describe('undefined required object', () => { | ||
// | ||
// before(() => { | ||
// | ||
// TestClass = React.createClass({ | ||
// propTypes : { | ||
// testRequiredObject : MomentPropTypes.momentObj.isRequired, | ||
// }, | ||
// render() { | ||
// return null; | ||
// }, | ||
// }); | ||
// | ||
// }); | ||
// | ||
// it('should have a warning for the undefined moment obj', (done) => { | ||
// const testElement = <TestClass testRequiredObject={undefined}/>; | ||
// TestUtils.renderIntoDocument(testElement); | ||
// | ||
// expect(warnings).to.be.an('array'); | ||
// expect(warnings.length).to.equal(1); | ||
// expect(warnings[0]).to.contain('required'); | ||
// expect(warnings[0]).to.contain('undefined'); | ||
// done(); | ||
// | ||
// }); | ||
// | ||
// }); | ||
describe('Missing optional object', () => { | ||
@@ -168,3 +227,3 @@ | ||
expect(warnings.length).to.equal(1); | ||
expect(warnings[0]).to.contain('Required prop'); | ||
expect(warnings[0]).to.contain('required'); | ||
done(); | ||
@@ -176,2 +235,62 @@ | ||
describe('null required string', () => { | ||
before(() => { | ||
TestClass = React.createClass({ | ||
propTypes : { | ||
testRequiredString : MomentPropTypes.momentString.isRequired, | ||
}, | ||
render() { | ||
return null; | ||
}, | ||
}); | ||
}); | ||
it('should have a warning for the null moment string', (done) => { | ||
const testElement = <TestClass testRequiredString={null}/>; | ||
TestUtils.renderIntoDocument(testElement); | ||
expect(warnings).to.be.an('array'); | ||
expect(warnings.length).to.equal(1); | ||
expect(warnings[0]).to.contain('required'); | ||
expect(warnings[0]).to.contain('null'); | ||
done(); | ||
}); | ||
}); | ||
// describe('undefined required string', () => { | ||
// | ||
// before(() => { | ||
// | ||
// TestClass = React.createClass({ | ||
// propTypes : { | ||
// testRequiredString : MomentPropTypes.momentString.isRequired, | ||
// }, | ||
// render() { | ||
// return null; | ||
// }, | ||
// }); | ||
// | ||
// }); | ||
// | ||
// it('should have a warning for the undefined moment string', (done) => { | ||
// | ||
// const testElement = <TestClass testRequiredString={undefined}/>; | ||
// TestUtils.renderIntoDocument(testElement); | ||
// | ||
// expect(warnings).to.be.an('array'); | ||
// expect(warnings.length).to.equal(1); | ||
// expect(warnings[0]).to.contain('required'); | ||
// expect(warnings[0]).to.contain('undefined'); | ||
// done(); | ||
// | ||
// }); | ||
// | ||
// }); | ||
describe('Missing optional string', () => { | ||
@@ -178,0 +297,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
162928
14
4449
3
1