This repository has been archived by the owner on Nov 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable no-console */ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import { Dummy } from './utils' | ||
import { compose, debug, withProps } from '../' | ||
|
||
describe('debug', () => { | ||
let consoleLog | ||
|
||
beforeEach(() => { | ||
consoleLog = console.log | ||
console.log = jest.fn() | ||
}) | ||
|
||
afterEach(() => { | ||
console.log = consoleLog | ||
}) | ||
|
||
it('should log compose', () => { | ||
const Component = compose( | ||
withProps({ a: 'b' }), | ||
debug(), | ||
withProps({ c: 'd' }), | ||
debug(), | ||
)(Dummy) | ||
|
||
shallow(<Component />).find(Dummy) | ||
expect(console.log).toHaveBeenCalledTimes(2) | ||
expect(console.log.mock.calls[0]).toEqual(['withProps(Component)', { a: 'b' }]) | ||
expect(console.log.mock.calls[1]).toEqual(['Dummy', { a: 'b', c: 'd' }]) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable no-param-reassign, no-console */ | ||
import createEagerFactory from './createEagerFactory' | ||
import getDisplayName from './getDisplayName' | ||
|
||
/** | ||
* Display the flow of props. | ||
* Very useful for debugging higher-order component stack. | ||
* | ||
* @static | ||
* @category Higher-order-components | ||
* @param {*} label A label displayed in console. | ||
* @param {Function} selector A props selector. | ||
* @returns {HigherOrderComponent} Returns a function that take a Component. | ||
* @example | ||
* | ||
* recompact.compose( | ||
* recompact.withProps({ foo: 'bar' }), | ||
* recompact.debug(), | ||
* recompact.renameProp('foo', 'className'), | ||
* recompact.debug(), | ||
* )('input') | ||
*/ | ||
const debug = (label, selector = x => x) => (BaseComponent) => { | ||
const factory = createEagerFactory(BaseComponent) | ||
label = label || getDisplayName(BaseComponent) | ||
return (props) => { | ||
console.log(label, selector(props)) | ||
return factory(props) | ||
} | ||
} | ||
|
||
export default debug |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ module.exports = { | |
{ | ||
test: /\.js$/, | ||
loader: 'babel-loader', | ||
exclude: /node_modules/, | ||
}, | ||
], | ||
}, | ||
|