Created
November 26, 2017 11:17
-
-
Save harunsmrkovic/a2744e740229b4863519750171da861f to your computer and use it in GitHub Desktop.
Fingerprint methods of an object
This file contains hidden or 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
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