Skip to content

Commit

Permalink
Remove not needed <div>
Browse files Browse the repository at this point in the history
Enzyme 3 fails with fragments, see enzymejs/enzyme#1213 (comment)
  • Loading branch information
tkrotoff committed Oct 9, 2017
1 parent 76bb6b8 commit fac7c2d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
4 changes: 2 additions & 2 deletions examples/Bootstrap4/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';

import { FormWithConstraints, FieldFeedback } from '../../src/index';
import { FieldFeedbacks, FormGroup, FormControlLabel, FormControlInput } from '../../src/Bootstrap4';
import { FormWithConstraints, FieldFeedbacks } from '../../src/index';
import { FieldFeedback, FormGroup, FormControlLabel, FormControlInput } from '../../src/Bootstrap4';

import './index.html';

Expand Down
8 changes: 4 additions & 4 deletions src/Bootstrap4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as PropTypes from 'prop-types';

import {
Input, FormWithConstraintsChildContext,
FieldFeedbacks as FieldFeedbacks_, FieldFeedbacksProps
FieldFeedback as FieldFeedback_, FieldFeedbackProps
} from './index';

export interface FormGroupProps extends React.HTMLAttributes<HTMLDivElement> {
Expand Down Expand Up @@ -132,12 +132,12 @@ export class FormControlInput extends React.Component<FormControlInputProps> {
}


const FieldFeedbacks: React.SFC<FieldFeedbacksProps> = props => {
const FieldFeedback: React.SFC<FieldFeedbackProps> = props => {
const { className, children, ...other } = props;
const classes = className !== undefined ? `${className} form-control-feedback` : 'form-control-feedback';
return <FieldFeedbacks_ {...other} className={classes}>{children}</FieldFeedbacks_>;
return <FieldFeedback_ {...other} className={classes}>{children}</FieldFeedback_>;
};
export { FieldFeedbacks };
export { FieldFeedback };


export interface LabelWithFormControlStyleProps extends React.LabelHTMLAttributes<HTMLLabelElement> {
Expand Down
4 changes: 2 additions & 2 deletions src/Enzyme.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ test('with Bootstrap4', () => {
<div>
<Bootstrap4.FormGroup for="username">
<Bootstrap4.FormControlInput name="username" value="" required />
<Bootstrap4.FieldFeedbacks for="username">
<FieldFeedbacks for="username">
<FieldFeedback when="*" />
</Bootstrap4.FieldFeedbacks>
</FieldFeedbacks>
</Bootstrap4.FormGroup>
</div>
);
Expand Down
3 changes: 1 addition & 2 deletions src/Enzyme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import * as React from 'react';
import { ShallowWrapper } from 'enzyme';

import { FieldFeedback, FieldFeedbackProps, FieldFeedbacks } from './index';
import * as Bootstrap4 from './Bootstrap4';

// Return the list of FieldFeedback associated with an input name
// Algorithm: find the FieldFeedbacks that matches the input name (for prop) and then return its children
function findFieldFeedbackList(wrapper: ShallowWrapper<{}, {}>, inputName: string) {
const fieldFeedbacksList = wrapper.findWhere(node => {
let found = false;
if (node.type() === FieldFeedbacks || node.type() === Bootstrap4.FieldFeedbacks) {
if (node.type() === FieldFeedbacks) {
if (node.prop('for') === inputName) {
found = true;
}
Expand Down
22 changes: 9 additions & 13 deletions src/FieldFeedbacks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe('render()', () => {
}
});
expect(component.html()).toEqual(
'<div><div><div class="error">Suffering from being missing</div></div></div>'
'<div><div class="error">Suffering from being missing</div></div>'
);
});

Expand All @@ -229,9 +229,7 @@ describe('render()', () => {
expect(form.fieldsStore.fields).toEqual({
username: fieldWithoutFeedback
});
expect(component.html()).toEqual(
'<div></div>'
);
expect(component.html()).toEqual(null);
});

describe('show prop', () => {
Expand Down Expand Up @@ -259,7 +257,7 @@ describe('render()', () => {
});

expect(component.html()).toEqual(
'<div><div class="error">Suffering from being missing</div><div class="error">Suffering from being missing</div><div class="error">Suffering from being missing</div></div>'
'<div class="error">Suffering from being missing</div><div class="error">Suffering from being missing</div><div class="error">Suffering from being missing</div>'
);
});

Expand Down Expand Up @@ -287,7 +285,7 @@ describe('render()', () => {
});

expect(component.html()).toEqual(
'<div><div class="error">Suffering from being missing</div></div>'
'<div class="error">Suffering from being missing</div>'
);
});

Expand Down Expand Up @@ -315,7 +313,7 @@ describe('render()', () => {
});

expect(component.html()).toEqual(
'<div><div class="error">Suffering from being missing</div><div class="info">Suffering from being missing</div></div>'
'<div class="error">Suffering from being missing</div><div class="info">Suffering from being missing</div>'
);
});
});
Expand Down Expand Up @@ -343,13 +341,11 @@ describe('reRender()', () => {
}
});
expect(component.html()).toEqual(
'<div><div class="error">Suffering from being missing</div></div>'
'<div class="error">Suffering from being missing</div>'
);

form.fieldsStore.updateField('username', fieldWithoutFeedback);
expect(component.html()).toEqual(
'<div></div>'
);
expect(component.html()).toEqual(null);
});

test('unknown field updated', () => {
Expand All @@ -373,7 +369,7 @@ describe('reRender()', () => {
}
});
expect(component.html()).toEqual(
'<div><div class="error">Suffering from being missing</div></div>'
'<div class="error">Suffering from being missing</div>'
);

const assert = console.assert;
Expand All @@ -387,7 +383,7 @@ describe('reRender()', () => {
console.assert = assert;

expect(component.html()).toEqual(
'<div><div class="error">Suffering from being missing</div></div>'
'<div class="error">Suffering from being missing</div>'
);
});
});
6 changes: 3 additions & 3 deletions src/FieldFeedbacks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EventEmitter } from './EventEmitter'; // FIXME See https://github.com/M
import Input from './Input';
import { FieldEvent } from './FieldsStore';

export interface FieldFeedbacksProps extends React.HTMLAttributes<HTMLDivElement> {
export interface FieldFeedbacksProps {
for: string;

/**
Expand Down Expand Up @@ -116,7 +116,7 @@ export class FieldFeedbacks extends withValidateEventEmitter(FieldFeedbacksCompo
}

render() {
const { for: fieldName, show, children, ...divProps } = this.props;
return <div {...divProps}>{children}</div>;
const { children } = this.props;
return children !== undefined ? children : null;
}
}

0 comments on commit fac7c2d

Please sign in to comment.