Skip to content

Instantly share code, notes, and snippets.

@Ranguro
Created January 31, 2019 22:01
Show Gist options
  • Save Ranguro/aca236219b9b04f3eb81660409c9f16b to your computer and use it in GitHub Desktop.
Save Ranguro/aca236219b9b04f3eb81660409c9f16b to your computer and use it in GitHub Desktop.
import React from 'react';
import PropTypes from 'prop-types';
export class Plot extends React.Component {
drawPlot() {
console.log('@@@@@@@@@@@@@ Called');
return true;
}
componentDidMount() {
this.drawPlot();
}
componentDidUpdate() {
this.drawPlot();
}
render() {
const { id } = this.props;
return (
<div id={id} className='class'></div>
);
}
}
Plot.propTypes = {
data: PropTypes.array.isRequired,
id: PropTypes.string.isRequired,
layout: PropTypes.object.isRequired
};
export function findChart() {
return Array.from(document.getElementsByClassName('chart'));
}
//In another file - test
import React from 'react';
import { mount } from 'enzyme';
import { Plot } from '<INSERT DIR HERE>';
describe('Plot', () => {
describe('<Plot/> Component', () => {
const data = [];
const id = 'Chart_1';
const layout = {};
const afterDrawMock = jest.fn();
const props = { id, data, layout, afterDraw: afterDrawMock };
const wrapper = mount(<Plot {...props}></Plot>);
const spyDrawPlot = jest.spyOn(wrapper.instance(), 'drawPlot');
it('should call drawPlot method', () => {
console.log('Call sequence');
wrapper.update();
expect(spyDrawPlot).toHaveBeenCalled();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment