errorMessage.test.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Form } from '../../index';
  2. import { noop } from 'lodash';
  3. import { BASE_CLASS_PREFIX } from '../../../semi-foundation/base/constants';
  4. const ErrorMessage = Form.ErrorMessage;
  5. function getEM(props) {
  6. return mount(<ErrorMessage {...props} />);
  7. }
  8. describe('Form-errorMessage', () => {
  9. it('className & style', () => {
  10. const props = {
  11. className: 'test',
  12. style: {
  13. color: 'red',
  14. },
  15. };
  16. const em = getEM(props);
  17. expect(em.exists('.test')).toEqual(true);
  18. expect(em.find('.test')).toHaveStyle('color', 'red');
  19. });
  20. it('error: string', () => {
  21. let stringError = 'semi error';
  22. const props = {
  23. error: stringError,
  24. };
  25. const em = getEM(props);
  26. expect(em.find(`.${BASE_CLASS_PREFIX}-form-field-error-message span`).text()).toEqual(stringError);
  27. });
  28. it('error: stringArray', () => {
  29. let arrayError = ['length error', 'size error'];
  30. const props = {
  31. error: arrayError,
  32. };
  33. const em = getEM(props);
  34. expect(em.find(`.${BASE_CLASS_PREFIX}-form-field-error-message span`).text()).toEqual(arrayError.join(', '));
  35. });
  36. it('error: reactNode', () => {
  37. let node = <div>semi error</div>;
  38. const props = {
  39. error: node,
  40. };
  41. const em = getEM(props);
  42. expect(em.find(`.${BASE_CLASS_PREFIX}-form-field-error-message`).contains(node)).toEqual(true);
  43. });
  44. it('error: null', () => {
  45. let arrayError = ['length error', 'size error'];
  46. const props = {
  47. error: null,
  48. };
  49. const em = getEM(props);
  50. expect(em.exists(`.${BASE_CLASS_PREFIX}-form-field-error-message`)).toEqual(false);
  51. });
  52. // it('showValidateIcon')
  53. // it('validateStatus')
  54. });