From d9040a104feb19df34e72605564891a1abf17080 Mon Sep 17 00:00:00 2001 From: zombiej Date: Sun, 22 Mar 2020 21:10:52 +0800 Subject: [PATCH] fix: emptyText --- .gitignore | 3 ++- examples/debug.tsx | 38 -------------------------------- src/Body/index.tsx | 1 + tests/Table.spec.js | 53 ++++++++++++++++++++++++++++++++------------- 4 files changed, 41 insertions(+), 54 deletions(-) delete mode 100644 examples/debug.tsx diff --git a/.gitignore b/.gitignore index 5c1105894..9fe6e0db3 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,5 @@ yarn.lock es/ .storybook .doc -!tests/__mocks__/rc-util/lib \ No newline at end of file +!tests/__mocks__/rc-util/lib +examples/debug.tsx \ No newline at end of file diff --git a/examples/debug.tsx b/examples/debug.tsx deleted file mode 100644 index 75d81651d..000000000 --- a/examples/debug.tsx +++ /dev/null @@ -1,38 +0,0 @@ -/* eslint-disable no-console,func-names,react/no-multi-comp */ -import React from 'react'; -import Table from '../src'; -import '../assets/index.less'; -import { ColumnsType } from '../src/interface'; - -const columns: ColumnsType = [ - { dataIndex: 'a', title: 'a' }, - { dataIndex: 'b', title: 'b' }, - { dataIndex: 'c', title: 'c', fixed: 'right', width: 200 }, -]; - -const Demo = () => { - const [showB, setShowB] = React.useState(true); - const myColumns = showB ? columns : columns.filter(({ title }) => title !== 'b'); - - return ( -
- - scroll={{ x: 2000 }} - tableLayout="auto" - columns={myColumns} - data={[{ a: 1, b: 2, c: 3, key: 1 }]} - /> - -
- ); -}; - -export default Demo; -/* eslint-enable */ diff --git a/src/Body/index.tsx b/src/Body/index.tsx index db3e48dd3..d503752e8 100644 --- a/src/Body/index.tsx +++ b/src/Body/index.tsx @@ -113,6 +113,7 @@ function Body({ getRowKey, getComponent, componentWidth, + emptyNode, ]); } diff --git a/tests/Table.spec.js b/tests/Table.spec.js index a7c81a555..d49af5b2d 100644 --- a/tests/Table.spec.js +++ b/tests/Table.spec.js @@ -40,21 +40,44 @@ describe('Table.Basic', () => { }); }); - it('renders empty text correctly', () => { - const wrapper1 = mount(createTable({ data: [], emptyText: 'No data' })); - const wrapper2 = mount(createTable({ data: [], emptyText: () => 'No data' })); - expect( - wrapper1 - .find('.rc-table-placeholder') - .hostNodes() - .text(), - ).toEqual('No data'); - expect( - wrapper2 - .find('.rc-table-placeholder') - .hostNodes() - .text(), - ).toEqual('No data'); + describe('renders empty text correctly', () => { + it('ReactNode', () => { + const wrapper = mount(createTable({ data: [], emptyText: 'No data' })); + expect( + wrapper + .find('.rc-table-placeholder') + .hostNodes() + .text(), + ).toEqual('No data'); + }); + + it('renderProps', () => { + const wrapper = mount(createTable({ data: [], emptyText: () => 'No data' })); + expect( + wrapper + .find('.rc-table-placeholder') + .hostNodes() + .text(), + ).toEqual('No data'); + }); + + it('effect update', () => { + const App = () => { + const [emptyText, setEmptyText] = React.useState('light'); + React.useEffect(() => { + setEmptyText('bamboo'); + }, []); + return ; + }; + const wrapper = mount(); + wrapper.update(); + expect( + wrapper + .find('.rc-table-placeholder') + .hostNodes() + .text(), + ).toEqual('bamboo'); + }); }); it('renders without header', () => {