This file contains 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
class TestPage extends React.PureComponent { | |
// | |
// Instance methods | |
fillTable = () => { | |
const { | |
tableValues, | |
} = this.state; | |
return ( |
This file contains 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
// Libraries | |
import React from 'react'; | |
import PropTypes from 'prop-types'; | |
// Components | |
import ButtonComponent from '../component/button-component/Button-Component'; | |
import NumericInputComponent from '../component/input-component/Numeric-Input-Component'; | |
import TableCellComponent from '../component/table-component/Table-Cell-Component'; | |
import TableComponent from '../component/table-component/Table-Component'; | |
import TableRowComponent from '../component/table-component/Table-Row-Component'; | |
// Context |
This file contains 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
describe('Interaction', () => { | |
let root; | |
let instance; | |
beforeEach(() => { | |
component = getComponent(); | |
root = component.root; | |
instance = root.instance; | |
}); |
This file contains 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
describe('Lifecycle', () => { | |
let instance; | |
let newComponent; | |
const updateComponent = (props) => ( | |
<TestPage {...{ ...defaultProps, ...props }} /> | |
); | |
beforeEach(() => { | |
component = getComponent(); | |
instance = component.root.instance; |
This file contains 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
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(); | |
}); |
This file contains 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
const component = getComponent({ | |
numCols: 10, | |
}); | |
const instance = component.root.instance; | |
console.log(instance.props.numCols); // 10 | |
console.log(instance.props.numRows); // 2 |
This file contains 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
const defaultProps = { | |
numCols: 2, | |
numRows: 2, | |
setNumRows: jest.fn(), | |
setNumCols: jest.fn(), | |
}; | |
// | |
const getComponent = (props) => renderer.create( |
This file contains 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
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'); |
This file contains 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
// Imports | |
// ------- | |
// Libraries | |
import React from 'react'; | |
import renderer from 'react-test-renderer'; | |
// Components | |
import { MyComponent } from '.../My-Component'; | |
// Mocks |
This file contains 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
export { | |
TestPage, | |
}; | |
// Default export | |
export default ( | |
withDatastore( | |
hasError()( | |
hasLoader()(TestPage), | |
), |
NewerOlder