Skip to content

Instantly share code, notes, and snippets.

@ruanlinos
Created June 24, 2022 22:25
Show Gist options
  • Save ruanlinos/4c54adb51e21d02827e80c177e3f3c82 to your computer and use it in GitHub Desktop.
Save ruanlinos/4c54adb51e21d02827e80c177e3f3c82 to your computer and use it in GitHub Desktop.
import {Provider} from 'react-redux'
import configureStore from 'redux-mock-store'
import {shallow, mount} from "enzyme";
import AddTool from "../AddTool";
import withProvider from "../../../hoc/with-provider";
import {render, screen, waitFor} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
describe('Add tool testing', () => {
const initialState = {
tools: [{
id: '1',
name: 'Tool 1',
link: 'https://www.google.com',
description: 'Description 1',
tags: [{
id: '1',
name: 'Tag 1'
}]
}],
toolsSearch: [],
isOnlyTag: false,
openModalAdd: false
}
const mockStore = configureStore()
const store = mockStore(initialState)
const Component = withProvider(AddTool, store)
it('should match with snapshot', () => {
const renderedComponent = shallow(
<Component/>
)
expect(renderedComponent).toMatchSnapshot()
})
it('should test AddTool component', () => {
const renderedComponent = mount(
<Component/>
)
renderedComponent.find("#submit-button")
.at(0)
.simulate("click")
})
it('should render error when submit form', () => {
const componentRender = mount(<Component/>)
componentRender.find("#submit-button").at(0).simulate("click")
})
it('should be able to click in cancel button', () => {
const componentRender = mount(<Component/>)
componentRender.find("#cancel-modal").at(0).simulate("click")
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment