Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jest test table rows and columns

I have a html table with the following data:


id | name

2 | C

1 | B

3 | A

I need to test the order of table items. I can get the rows using:

wrapper.findAll('table tr')

But how can I assert the order of rows comparing the columns (tds) ? Thanks.

like image 790
AjjjHsh Avatar asked Sep 13 '25 07:09

AjjjHsh


1 Answers

You can do something like this:

let $rows = wrapper.findAll('tbody > tr').wrappers

let column1 = $rows.map(row => {
  return row.
    findAll('td')
    .at(0)
    .text()
})

expect(column1[0]).toBe('text 1')
expect(column1[1]).toBe('text 2')
like image 145
Elder Carvalho Avatar answered Sep 15 '25 19:09

Elder Carvalho