refine new context API tests

This commit is contained in:
AllenFang 2018-07-22 16:21:15 +08:00
parent c0416fc307
commit 495875792f
3 changed files with 21 additions and 20 deletions

View File

@ -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(<SortCaret order={ Const.SORT_ASC } />);
const Children = wrapper.props().children({ bootstrap4: false });
wrapper = shallow(Children);
wrapper = shallowWithContext(
<SortCaret order={ Const.SORT_ASC } />,
{ bootstrap4: false }
);
});
it('should render caret correctly', () => {
@ -25,9 +26,10 @@ describe('SortCaret', () => {
describe(`when order prop is ${Const.SORT_DESC}`, () => {
beforeEach(() => {
wrapper = shallow(<SortCaret order={ Const.SORT_DESC } />);
const Children = wrapper.props().children({ bootstrap4: false });
wrapper = shallow(Children);
wrapper = shallowWithContext(
<SortCaret order={ Const.SORT_DESC } />,
{ 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(<SortCaret order={ Const.SORT_ASC } />);
const Children = wrapper.props().children({ bootstrap4: true });
wrapper = shallow(Children);
wrapper = shallowWithContext(<SortCaret order={ Const.SORT_ASC } />, { bootstrap4: true });
});
it('should render caret correctly', () => {
@ -55,9 +55,7 @@ describe('SortCaret', () => {
describe(`when order prop is ${Const.SORT_DESC}`, () => {
beforeEach(() => {
wrapper = shallow(<SortCaret order={ Const.SORT_DESC } />);
const Children = wrapper.props().children({ bootstrap4: true });
wrapper = shallow(Children);
wrapper = shallowWithContext(<SortCaret order={ Const.SORT_DESC } />, { bootstrap4: true });
});
it('should render caret correctly', () => {

View File

@ -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(<SortSymbol />);
const Children = wrapper.props().children({ bootstrap4: false });
wrapper = shallow(Children);
wrapper = shallowWithContext(<SortSymbol />, { 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(<SortSymbol />);
const Children = wrapper.props().children({ bootstrap4: true });
wrapper = shallow(Children);
wrapper = shallowWithContext(<SortSymbol />, { bootstrap4: true });
});
it('should render sort symbol correctly', () => {
expect(wrapper.length).toBe(1);

View File

@ -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);
};