Created
July 24, 2018 20:05
-
-
Save m0veax/7c127c17316ff70fd663a721e4623134 to your computer and use it in GitHub Desktop.
working enzyme example
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
// thanks to realPatriot_ from freenode/#react for his code | |
import { configure, shallow, mount } from 'enzyme'; | |
import Adapter from 'enzyme-adapter-react-16'; | |
import {Form, Dropdown} from 'semantic-ui-react'; | |
import React from 'react'; | |
import ScheduleVisualizerForm from './ScheduleVisualizerForm'; | |
configure({ adapter: new Adapter() }); | |
describe('<ScheduleVisualizerForm />', () => { | |
let props, wrapper | |
beforeEach(() => { | |
props = { | |
getSchedule: () => { | |
}, | |
}; | |
wrapper = shallow(<ScheduleVisualizerForm {...props} />); | |
}); | |
it('should have a `<Form>` element', () => { | |
expect(wrapper.find('Form').length).toBe(1); | |
}); | |
it('should have a `<Dropdown>` element', () => { | |
expect(wrapper.find('Dropdown').length).toBe(1); | |
}); | |
it('should have a `<DatePicker>` element', () => { | |
expect(wrapper.find('DatePicker').length).toBe(1); | |
}); | |
it('`<Form>` element should have a onSubmit attribute', () => { | |
const ScheduleForm = wrapper.find(Form); | |
expect(ScheduleForm.props().onSubmit).toBeDefined(); | |
}); | |
it('onSubmit attribute should be of type `function`', () => { | |
const ScheduleForm = wrapper.find(Form); | |
expect(typeof ScheduleForm.props().onSubmit === 'function').toBe(true); | |
}); | |
it('expects startDate state to be null', () => { | |
expect(wrapper.state().startDate).toEqual(null); | |
}); | |
it('expects channel state to be empty string', () => { | |
expect(wrapper.state().channel).toEqual(''); | |
}); | |
it('expects Dropdown to take a value', () => { | |
const dropDown = wrapper.find('Dropdown'); | |
dropDown.simulate('change',{target: { value: 'SH'}}); | |
// console.log(dropDown.get(0).ref.current.value, 'dropdown value') | |
console.log(wrapper.state().channel, 'whats the state') | |
// expect(wrapper.find('Dropdown').length).toBe(1); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment