Skip to content

Instantly share code, notes, and snippets.

View jvanderen1's full-sized avatar
🏋️‍♂️

Joshua Van Deren jvanderen1

🏋️‍♂️
  • Google, Inc.
  • Boulder, CO
View GitHub Profile
// Imports
// -------
// Libraries
import React from 'react';
import PropTypes from 'prop-types';
// Components
import ...
// Context
import ...
TestPage.propTypes = {
numCols: PropTypes.number, // from withDatastore
numRows: PropTypes.number, // from withDatastore
setNumCols: PropTypes.func, // from withDatastore
setNumRows: PropTypes.func, // from withDatastore
};
TestPage.defaultProps = {
numCols: 0,
numRows: 0,
export {
TestPage,
};
// Default export
export default (
withDatastore(
hasError()(
hasLoader()(TestPage),
),
// Imports
// -------
// Libraries
import React from 'react';
import renderer from 'react-test-renderer';
// Components
import { MyComponent } from '.../My-Component';
// Mocks
jest.mock('app/component/button-component/Button-Component', () => 'ButtonComponent');
jest.mock('app/component/input-component/Numeric-Input-Component', () => 'NumericInputComponent');
jest.mock('app/component/table-component/Table-Cell-Component', () => 'TableCellComponent');
jest.mock('app/component/table-component/Table-Component', () => 'TableComponent');
jest.mock('app/component/table-component/Table-Row-Component', () => 'TableRowComponent');
const defaultProps = {
numCols: 2,
numRows: 2,
setNumRows: jest.fn(),
setNumCols: jest.fn(),
};
//
const getComponent = (props) => renderer.create(
const component = getComponent({
numCols: 10,
});
const instance = component.root.instance;
console.log(instance.props.numCols); // 10
console.log(instance.props.numRows); // 2
describe('Rendering', () => {
it('renders default correctly', () => {
component = getComponent();
expect(component).toMatchSnapshot();
});
it('renders no data correctly', () => {
component = getComponent({ numCols: null, numRows: null });
expect(component).toMatchSnapshot();
});
describe('Lifecycle', () => {
let instance;
let newComponent;
const updateComponent = (props) => (
<TestPage {...{ ...defaultProps, ...props }} />
);
beforeEach(() => {
component = getComponent();
instance = component.root.instance;
describe('Interaction', () => {
let root;
let instance;
beforeEach(() => {
component = getComponent();
root = component.root;
instance = root.instance;
});