-
Notifications
You must be signed in to change notification settings - Fork 145
Improve validation with asynchronous pipeline #175
base: canary
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just use the wrapper.instance().validate(result)
to test the async function.
some refs:
@abz53378 async componentDidMount() {
const {refId, validation = {}, onDeploy, required = false} = this.props;
if (isEmpty(validation) && !required) {
// no validation
return;
}
const key = refId.getPathArr()[0];
this.callbackId = onDeploy(key, await this.validate);
} Then run test with waiting this lifecycle, is it a good way? it('should onDeploy be called', async () => {
const wrapper = mount(<WrapperComponent
{...props}
required
/>);
const instance = wrapper.instance();
await instance.componentDidMount();
expect(onDeploy).toBeCalledWith('posts', wrapper.instance().validate);
}); |
@Mosoc , I don't think it's a good way to make the |
@abz53378 it('should use customized validator with unexpected error', async () => {
const result = {
data: {
0: { url: ''}
}
};
const wrapper = mount(<WrapperComponent
{...props}
validation={
{
validator: () => {
const value = 1;
value = 2;
}
}
}
/>);
await wrapper.instance().validate(result)
expect(wrapper.state()).toMatchObject({
error: true,
errorInfo: [{
message: 'Error: "value" is read-only'
}]
})
}); |
I rechecked, and found that only one place needs to be modified. In docs folder, there is a galleryValidation. export const galleryValidation = {
validator: (content, reject) => {
if (content.length === 0) {
return reject("should at least have one photo");
}
}
}; Maybe it could be following snippet in new version: export const galleryValidation = {
validator: (content) => {
if (content.length === 0) {
return "should at least have one photo";
}
}
}; |
As reported in #173 #174
There are some todo:
schema
property to validation objectschema
is verified as non-empty object