Skip to content

Commit 77722f3

Browse files
Fix ESLint "Cannot reassign variables declared outside of the component/hook"
1 parent 16f0e1f commit 77722f3

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { render } from '@testing-library/react';
2-
import { useContext } from 'react';
32
import { TableBody } from '..';
43
import { Table, TableSection, TableSectionContext } from '../..';
54

@@ -15,26 +14,20 @@ describe('Table.Body', () => {
1514
});
1615

1716
it('exposes TableSectionContext', () => {
18-
let tableSection: TableSection = TableSection.NONE;
19-
20-
const TestComponent = () => {
21-
const tableContext = useContext(TableSectionContext);
22-
23-
if (tableSection !== tableContext) {
24-
tableSection = tableContext;
25-
}
26-
27-
return null;
28-
};
17+
const mock = jest.fn();
2918

3019
render(
3120
<Table>
3221
<TableBody>
33-
<TestComponent />
22+
<TableSectionContext.Consumer>
23+
{(section) => {
24+
return mock(section);
25+
}}
26+
</TableSectionContext.Consumer>
3427
</TableBody>
3528
</Table>,
3629
);
3730

38-
expect(tableSection).toBe(TableSection.BODY);
31+
expect(mock).toHaveBeenCalledWith(TableSection.BODY);
3932
});
4033
});
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { render } from '@testing-library/react';
2-
import { useContext } from 'react';
32
import { TableHead } from '..';
43
import { Table, TableSection, TableSectionContext } from '../..';
54

@@ -15,26 +14,20 @@ describe('Table.Head', () => {
1514
});
1615

1716
it('exposes TableSectionContext', () => {
18-
let tableSection: TableSection = TableSection.NONE;
19-
20-
const TestComponent = () => {
21-
const tableContext = useContext(TableSectionContext);
22-
23-
if (tableSection !== tableContext) {
24-
tableSection = tableContext;
25-
}
26-
27-
return null;
28-
};
17+
const mock = jest.fn();
2918

3019
render(
3120
<Table>
3221
<TableHead>
33-
<TestComponent />
22+
<TableSectionContext.Consumer>
23+
{(section) => {
24+
return mock(section);
25+
}}
26+
</TableSectionContext.Consumer>
3427
</TableHead>
3528
</Table>,
3629
);
3730

38-
expect(tableSection).toBe(TableSection.HEAD);
31+
expect(mock).toHaveBeenCalledWith(TableSection.HEAD);
3932
});
4033
});

0 commit comments

Comments
 (0)