Last active
June 8, 2017 01:33
-
-
Save jasongaare/383708aaac9168c872b5a0911e99886d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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