diff --git a/packages/react-bootstrap-table2/test/sort/caret.test.js b/packages/react-bootstrap-table2/test/sort/caret.test.js index d524496..50c89da 100644 --- a/packages/react-bootstrap-table2/test/sort/caret.test.js +++ b/packages/react-bootstrap-table2/test/sort/caret.test.js @@ -1,8 +1,8 @@ import React from 'react'; -import { shallow } from 'enzyme'; import Const from '../../src/const'; import SortCaret from '../../src/sort/caret'; +import { shallowWithContext } from '../test-helpers/new-context'; describe('SortCaret', () => { let wrapper; @@ -10,9 +10,10 @@ describe('SortCaret', () => { describe('when bootstrap4 context is false', () => { describe(`when order prop is ${Const.SORT_ASC}`, () => { beforeEach(() => { - wrapper = shallow(); - const Children = wrapper.props().children({ bootstrap4: false }); - wrapper = shallow(Children); + wrapper = shallowWithContext( + , + { bootstrap4: false } + ); }); it('should render caret correctly', () => { @@ -25,9 +26,10 @@ describe('SortCaret', () => { describe(`when order prop is ${Const.SORT_DESC}`, () => { beforeEach(() => { - wrapper = shallow(); - const Children = wrapper.props().children({ bootstrap4: false }); - wrapper = shallow(Children); + wrapper = shallowWithContext( + , + { bootstrap4: false } + ); }); it('should render caret correctly', () => { @@ -42,9 +44,7 @@ describe('SortCaret', () => { describe('when bootstrap4 context is true', () => { describe(`when order prop is ${Const.SORT_ASC}`, () => { beforeEach(() => { - wrapper = shallow(); - const Children = wrapper.props().children({ bootstrap4: true }); - wrapper = shallow(Children); + wrapper = shallowWithContext(, { bootstrap4: true }); }); it('should render caret correctly', () => { @@ -55,9 +55,7 @@ describe('SortCaret', () => { describe(`when order prop is ${Const.SORT_DESC}`, () => { beforeEach(() => { - wrapper = shallow(); - const Children = wrapper.props().children({ bootstrap4: true }); - wrapper = shallow(Children); + wrapper = shallowWithContext(, { bootstrap4: true }); }); it('should render caret correctly', () => { diff --git a/packages/react-bootstrap-table2/test/sort/symbol.test.js b/packages/react-bootstrap-table2/test/sort/symbol.test.js index 3aa88e1..6302b73 100644 --- a/packages/react-bootstrap-table2/test/sort/symbol.test.js +++ b/packages/react-bootstrap-table2/test/sort/symbol.test.js @@ -1,14 +1,12 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallowWithContext } from '../test-helpers/new-context'; import SortSymbol from '../../src/sort/symbol'; describe('SortSymbol', () => { let wrapper; beforeEach(() => { - wrapper = shallow(); - const Children = wrapper.props().children({ bootstrap4: false }); - wrapper = shallow(Children); + wrapper = shallowWithContext(, { bootstrap4: false }); }); it('should render sort symbol correctly', () => { expect(wrapper.length).toBe(1); @@ -20,9 +18,7 @@ describe('SortSymbol', () => { describe('if bootstrap4 prop is true', () => { beforeEach(() => { - wrapper = shallow(); - const Children = wrapper.props().children({ bootstrap4: true }); - wrapper = shallow(Children); + wrapper = shallowWithContext(, { bootstrap4: true }); }); it('should render sort symbol correctly', () => { expect(wrapper.length).toBe(1); diff --git a/packages/react-bootstrap-table2/test/test-helpers/new-context.js b/packages/react-bootstrap-table2/test/test-helpers/new-context.js new file mode 100644 index 0000000..cfbcc58 --- /dev/null +++ b/packages/react-bootstrap-table2/test/test-helpers/new-context.js @@ -0,0 +1,7 @@ +import { shallow } from 'enzyme'; + +export const shallowWithContext = (elem, context = {}) => { + const wrapper = shallow(elem); + const Children = wrapper.props().children(context); + return shallow(Children); +};