lucid-ui
Version:
A UI component library from AppNexus.
46 lines • 1.47 kB
JavaScript
import _noop from "lodash/noop";
import React from 'react';
import { common } from '../../util/generic-tests';
import { mount } from 'enzyme';
import Resizer from './Resizer';
jest.mock('element-resize-detector', function () {
return function () {
return {
listenTo: jest.fn(function (_element, handleResize) {
handleResize({
offsetWidth: 50,
offsetHeight: 100
});
}),
removeListener: jest.fn()
};
};
});
describe('Resizer', function () {
common(Resizer, {
exemptFunctionProps: ['children'],
getDefaultProps: function getDefaultProps() {
return {
children: function children() {
return /*#__PURE__*/React.createElement("div", null);
}
};
}
});
describe('render', function () {
it('should call the correct function when unmounted', function () {
var wrapper = mount( /*#__PURE__*/React.createElement(Resizer, null, _noop));
var instance = wrapper.instance();
expect(instance.resizeDetector.removeListener).not.toHaveBeenCalled();
wrapper.unmount();
expect(instance.resizeDetector.removeListener).toHaveBeenCalled();
});
});
describe('props', function () {
it('children should callback with width and height', function () {
var children = jest.fn();
mount( /*#__PURE__*/React.createElement(Resizer, null, children));
expect(children).toHaveBeenCalledWith(50, 100);
});
});
});