@@ -5,30 +5,35 @@ import { later, mockScrollTo } from "../util";
55describe ( "veTable instance methods" , ( ) => {
66 const TABLE_DATA = [
77 {
8+ rowkey : 0 ,
89 name : "John" ,
910 date : "1900-05-20" ,
1011 hobby : "coding and coding repeat" ,
1112 address : "No.1 Century Avenue, Shanghai" ,
1213 } ,
1314 {
15+ rowkey : 1 ,
1416 name : "Dickerson" ,
1517 date : "1910-06-20" ,
1618 hobby : "coding and coding repeat" ,
1719 address : "No.1 Century Avenue, Beijing" ,
1820 } ,
1921 {
22+ rowkey : 2 ,
2023 name : "Larsen" ,
2124 date : "2000-07-20" ,
2225 hobby : "coding and coding repeat" ,
2326 address : "No.1 Century Avenue, Chongqing" ,
2427 } ,
2528 {
29+ rowkey : 3 ,
2630 name : "Geneva" ,
2731 date : "2010-08-20" ,
2832 hobby : "coding and coding repeat" ,
2933 address : "No.1 Century Avenue, Xiamen" ,
3034 } ,
3135 {
36+ rowkey : 4 ,
3237 name : "Jami" ,
3338 date : "2020-09-20" ,
3439 hobby : "coding and coding repeat" ,
@@ -58,7 +63,7 @@ describe("veTable instance methods", () => {
5863 { field : "address" , key : "d" , title : "Address" } ,
5964 ] ;
6065
61- it ( "scroll method" , async ( ) => {
66+ it ( "scrollTo method" , async ( ) => {
6267 const wrapper = mount ( veTable , {
6368 propsData : {
6469 columns : COLUMNS ,
@@ -78,4 +83,31 @@ describe("veTable instance methods", () => {
7883 expect ( scrollToFn ) . toBeCalled ( ) ;
7984 expect ( scrollToFn ) . toHaveBeenCalledWith ( option ) ;
8085 } ) ;
86+
87+ it ( "scrollToRowKey method" , async ( ) => {
88+ let warnSpy = jest . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
89+
90+ const wrapper = mount ( veTable , {
91+ propsData : {
92+ columns : COLUMNS ,
93+ tableData : TABLE_DATA ,
94+ maxHeight : 50 ,
95+ rowKeyFieldName : "rowkey" ,
96+ } ,
97+ } ) ;
98+
99+ await later ( ) ;
100+
101+ const scrollToFn = mockScrollTo ( ) ;
102+
103+ const option = { top : 100 } ;
104+
105+ wrapper . vm . scrollToRowKey ( { rowKey : "" } ) ;
106+ expect ( warnSpy ) . toBeCalledWith ( `Row key can't be empty!` ) ;
107+
108+ wrapper . vm . scrollToRowKey ( { rowKey : 2 } ) ;
109+ expect ( scrollToFn ) . toBeCalled ( ) ;
110+
111+ warnSpy . mockRestore ( ) ;
112+ } ) ;
81113} ) ;
0 commit comments