-
-
Save kevgathuku/20a4de8ada9c8380d29951da8dead917 to your computer and use it in GitHub Desktop.
Touch Event Testing React Jest Enzyme
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 EventComponent from './EventComponent'; | |
import { mount } from 'enzyme'; | |
import { | |
createStartTouchEventObject, | |
createMoveTouchEventObject | |
} from './EventHelpers.js'; | |
describe('EventComponent', () => { | |
it('should render the component', ()=>{ | |
const component = mount((<EventComponent />)); | |
}); | |
it('should calculate when swiped', ()=>{ | |
const component = mount((<EventComponent />)); | |
expect(component.text()).toEqual('Component-'); | |
component.simulate('touchStart', | |
createStartTouchEventObject({ x: 100, y: 0 })); | |
component.simulate('touchMove', | |
createMoveTouchEventObject({ x: 150, y: 0 })); | |
component.simulate('touchEnd', | |
createMoveTouchEventObject({ x: 200, y: 0 })); | |
expect(component.text()).toEqual('Component-swiped'); | |
}); | |
it('should call onSwiped when swiped', ()=>{ | |
const onSwiped = jest.fn(); | |
const component = mount((<EventComponent onSwiped={onSwiped} />)); | |
component.simulate('touchStart', | |
createStartTouchEventObject({ x: 100, y: 0 })); | |
component.simulate('touchMove', | |
createMoveTouchEventObject({ x: 150, y: 0 })); | |
component.simulate('touchEnd', | |
createMoveTouchEventObject({ x: 200, y: 0 })); | |
expect(onSwiped).toHaveBeenCalled(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment