Skip to content

Commit

Permalink
fix(shallow): fix shallow test util
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Fedyashov committed Aug 31, 2017
1 parent 4d5e272 commit c990b34
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions test/utils/shallow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ import { ShallowWrapper } from 'enzyme'

const meetsName = (wrapper, name) => name === wrapper.type().name

const dive = wrapper => {
const dive = (wrapper) => {
/* eslint-disable no-param-reassign */
if (meetsName(wrapper, 'refHOC')) wrapper = wrapper.dive()
if (meetsName(wrapper, 'Ref')) wrapper = wrapper.dive()
/* eslint-enable */

return wrapper
}

class Wrapper extends ShallowWrapper {
shallow(options) {
return this.single('shallow', n => dive(new Wrapper(n, null, options)))
}
// Heads up! This monkey patch overrides behaviour of shallow() method of Enzyme
const shallowMethod = ShallowWrapper.prototype.shallow

ShallowWrapper.prototype.shallow = function (...args) {
return dive(shallowMethod.apply(this, ...args))
}

export default (...args) => dive(new Wrapper(...args))
export default (...args) => dive(new ShallowWrapper(...args))

0 comments on commit c990b34

Please sign in to comment.