Skip to content

Instantly share code, notes, and snippets.

@jasongaare
Last active June 8, 2017 01:33
Show Gist options
  • Save jasongaare/383708aaac9168c872b5a0911e99886d to your computer and use it in GitHub Desktop.
Save jasongaare/383708aaac9168c872b5a0911e99886d to your computer and use it in GitHub Desktop.
import React from 'react';
import { shallow } from 'enzyme';
import mockStore from 'redux-mock-store';
import sinon from 'sinon';
import { NativeModules } from 'react-native';
import CameraSettings from 'components/menu/CameraSettings';
const initialState = {
preferences: {
save_photos_locally: true,
open_to_camera: true,
},
};
jest.mock('NativeModules', () => {
return {
PhotoActions: {
saveToPhone: jest.fn(),
},
};
});
describe('Testing CameraSettings', () => {
const wrapper = shallow(
<CameraSettings />,
{ context: { store: mockStore(initialState) } },
);
const render = wrapper.dive();
it('renders as expected', () => {
expect(render).toMatchSnapshot();
});
const saveToPhoneSpy = sinon.spy(NativeModules.PhotoActions, 'saveToPhone');
it('calls actions as expected when toggling switches', () => {
render.find('Switch').forEach(child => {
child.simulate('valueChange');
});
expect(saveToPhoneSpy.calledOnce).toBe(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment