import React from 'react' import { shallow } from 'enzyme' import toJson from 'enzyme-to-json' import { AddMovie } from '../AddMovie' describe('components/AddMovie', () => { let component let instance let mutate let navigation beforeEach(() => { mutate = jest.fn() navigation = { navigate: jest.fn() } component = shallow() instance = component.instance() }) it('renders AddMovie', () => { expect(toJson(component)).toMatchSnapshot() }) describe('#insertMovie', () => { it('should call mutate with correct variables', async () => { try { await instance.insertMovie() expect(mutate).toHaveBeenCalledWith({ variables: { input: { imdbId: '', rating: 0, userId: 2 } } }) } catch (e) { throw new Error(e) } }) it('should navigate back to Feed', async () => { try { await instance.insertMovie() expect(navigation.navigate).toHaveBeenCalledWith('Feed') } catch (e) { throw new Error(e) } }) }) })