javascript - jest test table rows and columns - Stack Overflow

admin2025-04-17  0

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 paring the columns (tds) ? Thanks.

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 paring the columns (tds) ? Thanks.

Share Improve this question edited Oct 29, 2019 at 16:41 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Oct 29, 2019 at 13:52 AjjjHshAjjjHsh 2532 gold badges6 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

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')
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744885826a272527.html

最新回复(0)