-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02978c1
commit e72a527
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { Input } from 'antd'; | ||
import FormItem from '../src/FormItem'; | ||
import Form from '../src/Form'; | ||
|
||
describe('setValue from form', () => { | ||
it('setValue by name success', () => { | ||
const wrapper = mount( | ||
<Form> | ||
<FormItem id="test" value="test" > | ||
<Input /> | ||
</FormItem> | ||
</Form>); | ||
const form = wrapper.instance(); | ||
form.setValue('test', 'a'); | ||
expect(form.getValue('test')).toBe('a'); | ||
}); | ||
|
||
it('setValue all', () => { | ||
const wrapper = mount( | ||
<Form> | ||
<FormItem id="test" value="test" > | ||
<Input /> | ||
</FormItem> | ||
<FormItem id="test1" value="test1" > | ||
<Input /> | ||
</FormItem> | ||
</Form>); | ||
const form = wrapper.instance(); | ||
form.setValue({ | ||
test: 'a', | ||
test1: 'b', | ||
}); | ||
expect(form.getValue()).toEqual({ | ||
test: 'a', | ||
test1: 'b', | ||
}); | ||
}); | ||
|
||
it('check id when setValue', () => { | ||
expect(() => { | ||
const wrapper = mount( | ||
<Form> | ||
<FormItem id="test"> | ||
<Input /> | ||
</FormItem> | ||
</Form>); | ||
const form = wrapper.instance(); | ||
form.setValue('test1'); | ||
}).toThrow(/component with id: test1 is not exist in form./); | ||
}); | ||
}); |