Created
May 18, 2017 12:02
-
-
Save trotzig/f67ff0a56387621fc137adcdffc3ed0e to your computer and use it in GitHub Desktop.
Attempts at fixing custom proptypes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/packages/brigade-core/src/test/types/BrigadePropTypes_spec.js b/packages/brigade-core/src/test/types/BrigadePropTypes_spec.js | |
index 06a395a..26d3749 100644 | |
--- a/packages/brigade-core/src/test/types/BrigadePropTypes_spec.js | |
+++ b/packages/brigade-core/src/test/types/BrigadePropTypes_spec.js | |
@@ -7,30 +7,34 @@ import BrigadePropTypes from '../../types/BrigadePropTypes'; | |
function typeCheckFail(declaration, value, message) { | |
const props = { testProp: value }; | |
- const error = declaration( | |
- props, | |
- 'testProp', | |
- 'testComponent', | |
- 'prop', | |
- 'testProp' | |
- ); | |
- expect(error instanceof Error).toEqual(true); | |
- expect(error.message).toEqual(message); | |
+ const error = PropTypes.checkPropTypes({ | |
+ testProp: declaration, | |
+ }, props, 'prop', 'testComponent'); | |
+ expect(console.error.mock.calls.length).toBe(1); | |
+ expect(console.error.mock.calls[0][0]).toBe(`Warning: Failed prop type: ${message}`); | |
+ console.error.mockReset(); | |
} | |
function typeCheckPass(declaration, value) { | |
const props = { testProp: value }; | |
- const error = declaration( | |
- props, | |
- 'testProp', | |
- 'testComponent', | |
- 'prop', | |
- ); | |
- expect(error instanceof Error).toEqual(false); | |
+ PropTypes.checkPropTypes({ | |
+ testProp: declaration, | |
+ }, props, 'prop', 'testComponent'); | |
+ console.log(console.error.mock.calls); | |
+ expect(console.error.mock.calls.length).toBe(0); | |
+ console.error.mockReset(); | |
} | |
describe('BrigadePropTypes', () => { | |
+ beforeEach(() => { | |
+ //console.error = jest.fn(); | |
+ }); | |
+ | |
+ afterEach(() => { | |
+ console.error.mockReset(); | |
+ }); | |
+ | |
describe('createDateOrDateStringTypeChecker', () => { | |
it('should not warn when value is a valid Date representation', () => { | |
typeCheckPass(BrigadePropTypes.DateOrDateString, new Date()); | |
@@ -89,7 +93,7 @@ describe('BrigadePropTypes', () => { | |
}); | |
describe('createJSONArrayOfTypeChecker', () => { | |
- it('should not warn for valid json-array of', () => { | |
+ it.only('should not warn for valid json-array of', () => { | |
typeCheckPass(BrigadePropTypes.jsonArrayOf(PropTypes.number), '[1,2,3]'); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment