Skip to content

Commit 5ba4929

Browse files
Ensure error property is remove from props before passing to checkbox div (Radios does this currently) (#120)
Use jest `arrayContaining` to ensure index test does not consider array order when running test Pin TypeScript version, as tests were not running on latest 4.x that was installed automatically
1 parent 24b58b7 commit 5ba4929

File tree

5 files changed

+523
-70
lines changed

5 files changed

+523
-70
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"sass-loader": "10.1.1",
5353
"ts-jest": "^26.5.6",
5454
"ts-node": "^9.1.1",
55-
"typescript": "^4.2.4"
55+
"typescript": "4.2.4"
5656
},
5757
"peerDependencies": {
5858
"nhsuk-frontend": ">=4.0.0",

src/__tests__/index.test.ts

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,68 @@ import * as index from '../index';
22

33
describe('Index', () => {
44
it('contains all expected elements', () => {
5-
expect(Object.keys(index)).toEqual([
6-
'ActionLink',
7-
'BackLink',
8-
'Breadcrumb',
9-
'Button',
10-
'DefaultButton',
11-
'ButtonLink',
12-
'Card',
13-
'CareCard',
14-
'Checkboxes',
15-
'ContentsList',
16-
'DateInput',
17-
'Details',
18-
'DoDontList',
19-
'ErrorMessage',
20-
'ErrorSummary',
21-
'Fieldset',
22-
'Footer',
23-
'Form',
24-
'useFormContext',
25-
'Header',
26-
'Hero',
27-
'Hint',
28-
'Icons',
29-
'ArrowLeftIcon',
30-
'ArrowRightIcon',
31-
'ArrowRightCircleIcon',
32-
'ChevronLeftIcon',
33-
'ChevronRightIcon',
34-
'CloseIcon',
35-
'CrossIcon',
36-
'SmallEmdashIcon',
37-
'EmdashIcon',
38-
'MinusIcon',
39-
'PlusIcon',
40-
'SearchIcon',
41-
'TickIcon',
42-
'Images',
43-
'Input',
44-
'InsetText',
45-
'Label',
46-
'Container',
47-
'Col',
48-
'Row',
49-
'ListPanel',
50-
'NavAZ',
51-
'Pagination',
52-
'Radios',
53-
'ReviewDate',
54-
'Select',
55-
'SkipLink',
56-
'SummaryList',
57-
'Table',
58-
'Tag',
59-
'Textarea',
60-
'LedeText',
61-
'BodyText',
62-
'WarningCallout',
63-
'Clearfix',
64-
'ReadingWidth',
65-
]);
5+
expect(Object.keys(index)).toEqual(
6+
expect.arrayContaining([
7+
'ActionLink',
8+
'BackLink',
9+
'Breadcrumb',
10+
'Button',
11+
'DefaultButton',
12+
'ButtonLink',
13+
'Card',
14+
'CareCard',
15+
'Checkboxes',
16+
'ContentsList',
17+
'DateInput',
18+
'Details',
19+
'DoDontList',
20+
'ErrorMessage',
21+
'ErrorSummary',
22+
'Fieldset',
23+
'Footer',
24+
'Form',
25+
'useFormContext',
26+
'Header',
27+
'Hero',
28+
'Hint',
29+
'Icons',
30+
'ArrowLeftIcon',
31+
'ArrowRightIcon',
32+
'ArrowRightCircleIcon',
33+
'ChevronLeftIcon',
34+
'ChevronRightIcon',
35+
'CloseIcon',
36+
'CrossIcon',
37+
'SmallEmdashIcon',
38+
'EmdashIcon',
39+
'MinusIcon',
40+
'PlusIcon',
41+
'SearchIcon',
42+
'TickIcon',
43+
'Images',
44+
'Input',
45+
'InsetText',
46+
'Label',
47+
'Container',
48+
'Col',
49+
'Row',
50+
'ListPanel',
51+
'NavAZ',
52+
'Pagination',
53+
'Radios',
54+
'ReviewDate',
55+
'Select',
56+
'SkipLink',
57+
'SummaryList',
58+
'Table',
59+
'Tag',
60+
'Textarea',
61+
'LedeText',
62+
'BodyText',
63+
'WarningCallout',
64+
'Clearfix',
65+
'ReadingWidth',
66+
]),
67+
);
6668
});
6769
});

src/components/checkboxes/Checkboxes.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,8 @@ class Checkboxes extends PureComponent<CheckboxesProps, CheckboxesState> {
8181
const { children, ...rest } = this.props;
8282
return (
8383
<FormGroup<CheckboxesProps> inputType="checkboxes" {...rest}>
84-
{({
85-
className,
86-
name,
87-
id,
88-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
89-
idPrefix,
90-
...restRenderProps
91-
}) => {
84+
{/* eslint-disable-next-line @typescript-eslint/no-unused-vars */}
85+
{({ className, name, id, idPrefix, error, ...restRenderProps }) => {
9286
this.resetBoxIds();
9387
const containsConditional = this.state.conditionalBoxes.length > 0;
9488
const contextValue: ICheckboxContext = {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { mount } from 'enzyme';
2+
import React from 'react';
3+
import Checkboxes from '../Checkboxes';
4+
5+
describe('Checkboxes', () => {
6+
it('matches snapshot', () => {
7+
const element = mount(
8+
<Checkboxes id="example" name="example">
9+
<Checkboxes.Box value="animal">Waste from animal carcasses</Checkboxes.Box>
10+
<Checkboxes.Box value="mines">Waste from mines or quarries</Checkboxes.Box>
11+
<Checkboxes.Box value="farm">Farm or agricultural waste</Checkboxes.Box>
12+
</Checkboxes>,
13+
);
14+
expect(element).toMatchSnapshot();
15+
element.unmount();
16+
});
17+
18+
it('matches snapshot with string error', () => {
19+
const element = mount(
20+
<Checkboxes id="example" name="example" error="Example error">
21+
<Checkboxes.Box value="animal">Waste from animal carcasses</Checkboxes.Box>
22+
<Checkboxes.Box value="mines">Waste from mines or quarries</Checkboxes.Box>
23+
<Checkboxes.Box value="farm">Farm or agricultural waste</Checkboxes.Box>
24+
</Checkboxes>,
25+
);
26+
expect(element).toMatchSnapshot();
27+
element.unmount();
28+
});
29+
30+
it('matches snapshot with boolean error', () => {
31+
const element = mount(
32+
<Checkboxes id="example" name="example" error={true}>
33+
<Checkboxes.Box value="animal">Waste from animal carcasses</Checkboxes.Box>
34+
<Checkboxes.Box value="mines">Waste from mines or quarries</Checkboxes.Box>
35+
<Checkboxes.Box value="farm">Farm or agricultural waste</Checkboxes.Box>
36+
</Checkboxes>,
37+
);
38+
expect(element).toMatchSnapshot();
39+
element.unmount();
40+
});
41+
});

0 commit comments

Comments
 (0)