describe('Avatars Component', () => { const mockFn = jest.fn() const comp = <Avatars back={mockFn} of="user" group={1} /> mockAxiosRequest('get-avatars', avatarsMockArray) it('should match snapshot', () => { const tree = create(comp).toJSON() expect(tree).toMatchSnapshot() }) it('should call componentDidMount and get avatars', async () => { const wrapper = shallow(comp) await wrapper.instance().componentDidMount() expect(wrapper.state().avatars).toBeArrayOfSize(4) expect(wrapper.state().avatars).toIncludeAnyMembers([avatars[0]]) }) it('should simulate click event for closing the modal', () => { const wrapper = shallow(comp) wrapper.find('.pro_ava_close').simulate('click') }) })
describe('PostTags Component', () => { const props = { post_id: 11, tags_count: 1, } it('should match snapshot', () => { const tree = create(<PostTags {...props} />).toJSON() expect(tree).toMatchSnapshot() }) it('should match snapshot with null when tags_count == 0', () => { const tree = create(<PostTags post_id={11} tags_count={0} />).toJSON() expect(tree).toMatchSnapshot() }) it('should show <Tags/> when showTags == true', () => { const wrapper = shallow(<PostTags {...props} />) wrapper.setState({ showTags: true }) expect(wrapper.find('Connect(Tags)').exists()).toBe(true) }) it('should decrement tags_count', () => { const wrapper = shallow(<PostTags {...props} />) expect(wrapper.state().tags_count).toBe(1) wrapper.instance().decrementTags() expect(wrapper.state().tags_count).toBe(0) }) })
wrapper.instance().forceUpdate() return wrapper
describe('PostBottom Component', () => { const postDetails = { comments_count: 2, post_id: 44, when: 'feed', user: 7, comments: [], } it('should match snapshot', () => { const tree = create( <Provider store={mockStore}> <PostBottom postDetails={postDetails} /> </Provider> ).toJSON() expect(tree).toMatchSnapshot() }) it('should increments comments count', () => { const wrapper = shallow(<PurePostBottom postDetails={postDetails} />) expect(wrapper.state().comments_count).toBe(2) wrapper.instance().incrementComments() expect(wrapper.state().comments_count).toBe(3) }) })
['shares_count', 1], ]) wrapper.instance().incrementWhat('likes_count') wrapper.instance().incrementWhat('shares_count') expect(wrapper.state()).toContainEntries([ ['likes_count', 2], ['shares_count', 1], ]) wrapper.instance().decrementWhat('likes_count') wrapper.instance().decrementWhat('shares_count') expect(wrapper.state()).toContainEntries([ ['likes_count', 0],
test('calling toggleAddPostSection dispatches toggleAddPost', t => { const wrapper = shallow( <App {...props} /> ); wrapper.instance().toggleAddPostSection(); t.truthy(dispatch.calledOnce); t.truthy(dispatch.calledWith(toggleAddPost())); });
it('should set tipVisible to false when handleLeave is called', () => { const graphData = {nodes: [], links: [], summary: {tracesConsidered: 0, traceLimitReached: false}}; const instance = shallow(<ServiceInsightsGraph graphData={graphData} />).instance(); instance.state.tipVisible = true; instance.handleLeave(); expect(instance.state.tipVisible).to.equal(false); });
describe('Menu', () => { let instance beforeEach(() => { instance = shallow(<Menu />).instance() lib.isExistingUser = jest.fn().mockReturnValue('lib.isExistingUser') }) test('existingUser returns from isExistingUser', () => { expect(instance.existingUser()).toEqual('lib.isExistingUser') }) })
describe("<Counter />", () => { it("properly increments and decrements the counter", () => { const wrapper = shallow(<Counter />); expect(wrapper.state("count")).toBe(0); wrapper.instance().increment(); expect(wrapper.state("count")).toBe(1); wrapper.instance().decrement(); expect(wrapper.state("count")).toBe(0); }); });
it('renders correctly', () => { const TestComponent = connect(Test); const testFn = jest.fn(); const options = {context: {strings: {}, language: {subscribe: testFn}}}; const wrapper = shallow(<TestComponent/>, options); expect(wrapper).toMatchSnapshot(); expect(wrapper.props()).toEqual(options.context); //mock component did mount behaviour wrapper.instance().subscribe(); expect(testFn).toHaveBeenCalled(); });
it("should reset when props.selectedIntent change", () => { const resetSpy = jest.fn(); const wrapper = shallow(<IntentContainerBase {...defaultProps} />); wrapper.instance().reset = resetSpy; wrapper.update(); wrapper.setProps({ selectedIntent: newSelectedIntent, }); expect(resetSpy).toHaveBeenCalled(); });
it('should set state values when handleLineHover is called', () => { const graphData = {nodes: [], links: [], summary: {tracesConsidered: 0, traceLimitReached: false}}; const instance = shallow(<ServiceInsightsGraph graphData={graphData} />).instance(); instance.handleLineHover({}, 9, 10, {bar: 'baz'}); expect(instance.state.tipPos).to.deep.equal({x: 9, y: 10}); expect(instance.state.tipVisible).to.equal(true); expect(instance.state.tipType).to.equal('line'); expect(instance.state.tipData).to.deep.equal({bar: 'baz'}); });
describe('PlaylistCard component', () => { it('should render properly before image load', () => { const playlistCard = shallow(<PlaylistCard playlist={playlist} />); expect(playlistCard).toMatchSnapshot(); }); it('should render properly after image load', () => { const playlistCard = shallow(<PlaylistCard playlist={playlist} />); playlistCard.instance().onImageLoad(); expect(playlistCard).toMatchSnapshot(); }); });