File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import { mount } from 'enzyme' ;
3+ import Table from '../src' ;
4+
5+ describe ( 'Table.Cell' , ( ) => {
6+ it ( 'shouldCellUpdate' , ( ) => {
7+ let renderTime = 0 ;
8+
9+ const Demo = ( ) => {
10+ const [ , forceUpdate ] = React . useState ( { } ) ;
11+
12+ return (
13+ < >
14+ < Table
15+ data = { [ { key : 'light' } ] }
16+ columns = { [
17+ {
18+ shouldCellUpdate : ( record , prevRecord ) => prevRecord . key !== record . key ,
19+ dataIndex : 'key' ,
20+ render : value => {
21+ renderTime += 1 ;
22+ return value ;
23+ } ,
24+ } ,
25+ ] }
26+ />
27+ < button
28+ type = "button"
29+ onClick = { ( ) => {
30+ forceUpdate ( { } ) ;
31+ } }
32+ />
33+ </ >
34+ ) ;
35+ } ;
36+
37+ const wrapper = mount ( < Demo /> ) ;
38+
39+ for ( let i = 0 ; i < 100 ; i += 1 ) {
40+ wrapper . find ( 'button' ) . simulate ( 'click' ) ;
41+ expect ( renderTime ) . toEqual ( 1 ) ;
42+ }
43+ } ) ;
44+ } ) ;
You can’t perform that action at this time.
0 commit comments