Skip to content

Instantly share code, notes, and snippets.

@charisschomba
Created February 20, 2019 10:01
Show Gist options
  • Save charisschomba/caa6ea390813c36e0c17ad31edc6e0a8 to your computer and use it in GitHub Desktop.
Save charisschomba/caa6ea390813c36e0c17ad31edc6e0a8 to your computer and use it in GitHub Desktop.
import React from 'react';
import { mount } from 'enzyme';
import UsersDetails from '../../../components/Users/USersDetails';
import user from '../../../__mocks__/fetchUserData';
const state = {
deleteModalOpen: false,
selectedUser: null,
};
const props = {
deleteUser: jest.fn(),
};
const wrapper = mount(
<UsersDetails users={user.fetchedUsersData} {...props} {...state} />,
);
describe('<UsersDetails /> ', () => {
it('DisplayUsers with necessary data', () => {
expect(wrapper.find('Table').length).toBe(1);
});
it('test hideDeleteModal', () => {
const handleClickSpy = jest.spyOn(wrapper.instance(), 'hideDeleteModal');
wrapper.instance().hideDeleteModal();
expect(handleClickSpy.mock.calls.length).toEqual(1);
});
it('test showDeleteModal', () => {
const handleClickSpy = jest.spyOn(wrapper.instance(), 'showDeleteModal');
wrapper.instance().showDeleteModal();
expect(handleClickSpy.mock.calls.length).toEqual(1);
});
it('test handleDelete', () => {
const handleClickSpy = jest.spyOn(wrapper.instance(), 'handleDelete');
wrapper.instance().state = { selectedUser: user.fetchedUsersData };
wrapper.instance().handleDelete();
expect(handleClickSpy.mock.calls.length).toEqual(1);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment