UNPKG

principles-ui-components

Version:

Supporting UI controller for Tizen TV web application, which developed base on React Framework.

47 lines (38 loc) 2.01 kB
import React from 'react'; import {shallow, mount} from 'enzyme'; import Image from '../UI_Component/common/Image'; describe('<Image />', () => { const OSD = { t: 0, l: 0, w: 285, h: 285, url: 'https://u.scdn.co/images/pl/default/e714636cd9f486a6e5e83339893ced444efb6035',}; it('Image unit test, reset props, calls react lifecicle function', () => { const spyDidMount = jest.spyOn(Image.prototype, 'componentDidMount'); const spyWillReceiveProps = jest.spyOn(Image.prototype, 'componentWillReceiveProps'); const spyshouldUpdate = jest.spyOn(Image.prototype, 'shouldComponentUpdate'); const spyDidUpdate = jest.spyOn(Image.prototype, 'componentDidUpdate'); const spyWillUnmount = jest.spyOn(Image.prototype, 'componentWillUnmount'); const imageWrapper = mount(<Image />); expect(imageWrapper.props().OSD).toEqual({ t: 0, l: 0, w: 285, h: 285, url: '',}); expect(spyDidMount).toHaveBeenCalled(); spyDidMount.mockReset(); spyDidMount.mockRestore(); // console.log('calls componentDidMount'); imageWrapper.setProps({OSD}); expect(imageWrapper.props().OSD).toEqual({ t: 0, l: 0, w: 285, h: 285, url: 'https://u.scdn.co/images/pl/default/e714636cd9f486a6e5e83339893ced444efb6035',}); expect(spyWillReceiveProps).toHaveBeenCalled(); spyWillReceiveProps.mockReset(); spyWillReceiveProps.mockRestore(); // console.log('calls componentWillReceiveProps'); expect(spyshouldUpdate).toHaveBeenCalled(); spyshouldUpdate.mockReset(); spyshouldUpdate.mockRestore(); // console.log('calls shouldComponentUpdate'); expect(spyDidUpdate).toHaveBeenCalled(); spyDidUpdate.mockReset(); spyDidUpdate.mockRestore(); // console.log('calls componentDidUpdate'); imageWrapper.unmount(); expect(spyWillUnmount).toHaveBeenCalled(); spyWillUnmount.mockReset(); spyWillUnmount.mockRestore(); // console.log('calls componentWillUnmount'); }); });