Skip to content

Commit be3f384

Browse files
authored
Merge pull request #50 from springload/chore/update-tests
Chore/update tests
2 parents 2f597b3 + ff29cbd commit be3f384

File tree

6 files changed

+55
-144
lines changed

6 files changed

+55
-144
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
> All notable changes to this project are documented in this file.
44
> This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
55
6-
## [[v2.0.1]](https://github.com/springload/react-accessible-accordion/releases/tag/v2.0.0)
7-
8-
Version 2.1 represents changes to devDependencies only, and should have no backward-incompatible effect on this library.
6+
## [[v2.0.1]](https://github.com/springload/react-accessible-accordion/releases/tag/v2.0.1)
97

108
### Changed
119

1210
* Upgrade all dev-dependencies except the eslint configs.
11+
* Replace snapshot tests with explicit assertions in AccordionItemBody and AccordionItemTitle.
12+
* Add specific assertions to tests in accordionStore.
1313

1414
## [[v2.0.1]](https://github.com/springload/react-accessible-accordion/releases/tag/v2.0.1)
1515

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`AccordionItemBody renders correctly with different className 1`] = `
4-
<div
5-
aria-hidden={true}
6-
aria-labelledby="accordion__title-asdf-1234"
7-
className="testCSSClass accordion__body--hidden"
8-
id="accordion__body-asdf-1234"
9-
role="tabpanel"
10-
>
11-
<div>
12-
Fake body
13-
</div>
14-
</div>
15-
`;
16-
173
exports[`AccordionItemBody renders correctly with min params 1`] = `
184
<div
195
aria-hidden={true}
@@ -27,17 +13,3 @@ exports[`AccordionItemBody renders correctly with min params 1`] = `
2713
</div>
2814
</div>
2915
`;
30-
31-
exports[`AccordionItemBody renders correctly with prefixClass 1`] = `
32-
<div
33-
aria-hidden={true}
34-
aria-labelledby="accordion__title-asdf-1234"
35-
className="accordion__body testCSSClass--hidden"
36-
id="accordion__body-asdf-1234"
37-
role="tabpanel"
38-
>
39-
<div>
40-
Fake body
41-
</div>
42-
</div>
43-
`;

src/AccordionItemBody/accordion-item-body.spec.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,23 @@ describe('AccordionItemBody', () => {
3737
});
3838

3939
it('renders correctly with different className', () => {
40-
const tree = renderer
41-
.create(
42-
<Provider accordionStore={accordionStore} uuid={uuid}>
43-
<AccordionItemBody className="testCSSClass">
44-
<div>Fake body</div>
45-
</AccordionItemBody>
46-
</Provider>,
47-
)
48-
.toJSON();
49-
expect(tree).toMatchSnapshot();
40+
const className = 'className';
41+
const wrapper = mount(
42+
<Provider accordionStore={accordionStore} uuid={uuid}>
43+
<AccordionItemBody className={className} />
44+
</Provider>,
45+
);
46+
expect(wrapper.find('div').hasClass(className)).toEqual(true);
5047
});
5148

52-
it('renders correctly with prefixClass', () => {
53-
const tree = renderer
54-
.create(
55-
<Provider accordionStore={accordionStore} uuid={uuid}>
56-
<AccordionItemBody hideBodyClassName="testCSSClass--hidden">
57-
<div>Fake body</div>
58-
</AccordionItemBody>
59-
</Provider>,
60-
)
61-
.toJSON();
62-
expect(tree).toMatchSnapshot();
49+
it('renders correctly with different hideBodyClassName', () => {
50+
const hideBodyClassName = 'hideBodyClassName';
51+
const wrapper = mount(
52+
<Provider accordionStore={accordionStore} uuid={uuid}>
53+
<AccordionItemBody hideBodyClassName={hideBodyClassName} />
54+
</Provider>,
55+
);
56+
expect(wrapper.find('div').hasClass(hideBodyClassName)).toEqual(true);
6357
});
6458

6559
it('renders null if an associated AccordionItem is not registered in accordionStore', () => {
Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`AccordionItemTitle doesn't respect hideBodyClassName when collapsed 1`] = `
4-
<div
5-
aria-controls="accordion__body-item-two-uuid"
6-
aria-expanded={true}
7-
className="accordion__title"
8-
disabled={false}
9-
id="accordion__title-item-two-uuid"
10-
onClick={[Function]}
11-
onKeyPress={[Function]}
12-
role="button"
13-
tabIndex="0"
14-
>
15-
<div>
16-
Fake title
17-
</div>
18-
</div>
19-
`;
20-
21-
exports[`AccordionItemTitle renders correctly with different className 1`] = `
22-
<div
23-
aria-controls="accordion__body-item-one-uuid"
24-
aria-expanded={false}
25-
className="testCSSClass"
26-
disabled={false}
27-
id="accordion__title-item-one-uuid"
28-
onClick={[Function]}
29-
onKeyPress={[Function]}
30-
role="button"
31-
tabIndex="0"
32-
>
33-
<div>
34-
Fake Title
35-
</div>
36-
</div>
37-
`;
38-
393
exports[`AccordionItemTitle renders correctly with min params 1`] = `
404
<div
415
aria-controls="accordion__body-item-one-uuid"
@@ -53,21 +17,3 @@ exports[`AccordionItemTitle renders correctly with min params 1`] = `
5317
</div>
5418
</div>
5519
`;
56-
57-
exports[`AccordionItemTitle renders with different hideBodyClassName 1`] = `
58-
<div
59-
aria-controls="accordion__body-item-one-uuid"
60-
aria-expanded={false}
61-
className="accordion__title testCSSClass--hidden"
62-
disabled={false}
63-
id="accordion__title-item-one-uuid"
64-
onClick={[Function]}
65-
onKeyPress={[Function]}
66-
role="button"
67-
tabIndex="0"
68-
>
69-
<div>
70-
Fake title
71-
</div>
72-
</div>
73-
`;

src/AccordionItemTitle/accordion-item-title.spec.js

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,48 +46,39 @@ describe('AccordionItemTitle', () => {
4646
});
4747

4848
it('renders correctly with different className', () => {
49-
const tree = renderer
50-
.create(
51-
<AccordionItemTitle
52-
className="testCSSClass"
53-
accordionStore={accordionStore}
54-
uuid="item-one-uuid"
55-
>
56-
<div>Fake Title</div>
57-
</AccordionItemTitle>,
58-
)
59-
.toJSON();
60-
expect(tree).toMatchSnapshot();
49+
const className = 'className';
50+
const wrapper = mount(
51+
<AccordionItemTitle
52+
className={className}
53+
accordionStore={accordionStore}
54+
uuid="item-one-uuid"
55+
/>,
56+
);
57+
expect(wrapper.find('div').hasClass(className)).toEqual(true);
6158
});
6259

6360
it('renders with different hideBodyClassName', () => {
64-
const tree = renderer
65-
.create(
66-
<AccordionItemTitle
67-
hideBodyClassName="testCSSClass--hidden"
68-
accordionStore={accordionStore}
69-
uuid="item-one-uuid"
70-
>
71-
<div>Fake title</div>
72-
</AccordionItemTitle>,
73-
)
74-
.toJSON();
75-
expect(tree).toMatchSnapshot();
61+
const hideBodyClassName = 'hideBodyClassName';
62+
const wrapper = mount(
63+
<AccordionItemTitle
64+
hideBodyClassName={hideBodyClassName}
65+
accordionStore={accordionStore}
66+
uuid="item-one-uuid"
67+
/>,
68+
);
69+
expect(wrapper.find('div').hasClass(hideBodyClassName)).toEqual(true);
7670
});
7771

78-
it("doesn't respect hideBodyClassName when collapsed", () => {
79-
const tree = renderer
80-
.create(
81-
<AccordionItemTitle
82-
hideBodyClassName="testCSSClass--hidden"
83-
accordionStore={accordionStore}
84-
uuid="item-two-uuid"
85-
>
86-
<div>Fake title</div>
87-
</AccordionItemTitle>,
88-
)
89-
.toJSON();
90-
expect(tree).toMatchSnapshot();
72+
it("doesn't present hideBodyClassName when collapsed", () => {
73+
const hideBodyClassName = 'hideBodyClassName';
74+
const wrapper = mount(
75+
<AccordionItemTitle
76+
hideBodyClassName={hideBodyClassName}
77+
accordionStore={accordionStore}
78+
uuid="item-two-uuid"
79+
/>,
80+
);
81+
expect(wrapper.find('div').hasClass(hideBodyClassName)).toEqual(false);
9182
});
9283

9384
it('renders correctly when pressing enter', async () => {

src/accordionStore/accordionStore.spec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ describe('accordionStore', () => {
5050
expect(store.items.length).toEqual(2);
5151
store.removeItem('foo');
5252
expect(store.items.length).toEqual(1);
53+
expect(store.items.find(item => item.uuid === 'foo')).toEqual(
54+
undefined,
55+
);
5356
});
5457

5558
it('can modify the expanded property of an item', () => {
@@ -71,7 +74,12 @@ describe('accordionStore', () => {
7174
});
7275

7376
store.setExpanded('foo', false);
74-
expect(store.items.filter(item => item.expanded).length).toEqual(1);
77+
78+
const expandedItems = store.items.filter(item => item.expanded);
79+
expect(expandedItems.length).toEqual(1);
80+
expect(expandedItems.find(item => item.uuid === 'foo')).toEqual(
81+
undefined,
82+
);
7583
});
7684

7785
it('will collapse any open item if accordion=true', () => {

0 commit comments

Comments
 (0)