Skip to content

Instantly share code, notes, and snippets.

@harunsmrkovic
Created November 26, 2017 11:17
Show Gist options
  • Save harunsmrkovic/a2744e740229b4863519750171da861f to your computer and use it in GitHub Desktop.
Save harunsmrkovic/a2744e740229b4863519750171da861f to your computer and use it in GitHub Desktop.
Fingerprint methods of an object
import React from 'react'
import { shallow } from 'enzyme'
import { RectangleBase as Rectangle } from '.'
const defaultProps = {
width: 10,
height: 10,
x: 1,
y: 1
}
const fingerprint = (trackFns = []) => {
const log = []
const spy = fn => (...args) => {
log.push({ fn, args })
}
return {
mocks: trackFns.reduce(
(tracker, key) => ({ ...tracker, [key]: spy(key) }),
{}
),
log
}
}
describe('Rectangle', () => {
describe('radius', () => {
describe('when it has no radius', () => {
it('calls fillRect on ctx with proper values', () => {
const ctx = fingerprint([
'beginPath',
'moveTo',
'lineTo',
'stroke',
'closePath'
])
shallow(<Rectangle {...defaultProps} ctx={ctx.mocks} />)
expect(ctx.log).toMatchSnapshot()
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment