0.2.3 • Published 6 years ago
@scott-m-sarsfield/spy-on-render v0.2.3
@scott-m-sarsfield/spy-on-render
Spy on React components in Jasmine tests.
DOES NOT WORK WITH FUNCTIONAL COMPONENTS. They're functions!
HOWEVER, I'VE ADDED SOME USEFUL ERROR MESSAGES.
Installation
npm install spy-on-render
Put this in your spec_helper.js
:
require('spy-on-render');
Usage
spyOnRender
Just call it:
spyOnRender(Component);
By default, it won't render anything. If you want to render normally:
spyOnRender(Component).and.callThrough();
spyOnRender
returns a spy, so you can do whatever you want with it.
Matchers
was the component rendered?
expect(Component).toHaveBeenRendered();
with specific properties?
expect(Component).toHaveBeenRenderedWithProps({
className: 'whatever',
otherProp: 'whocares'
});
Helpers
what props were rendered last?
propsOnLastRender(Component)
what props were rendered at some other point in time?
propsOnRenderAt(Component, i)
Contributing
If you need to publish the package,
gulp build
cd dist
npm publish
(don't forget to increment the version)