Karma/Jasmine test throwing error when checking for table order

Karma/Jasmine test throwing error when checking for table order

gwar9gwar9 Posts: 2Questions: 1Answers: 0

Hi, I am writing test for all my datatable options. I am currently trying to pass a test where the order of a column is ascending

My test looks like

it("table first column is in ascending order", function () {
    const order = [[0, 'asc']]```
    const html = `<table id="reference">
    <thead>
    <tr><th>Col 1</th><th>Col 2</th><th>Col 3</th></tr>
    </thead>
    <tbody>
    <tr><td>Date 1</td><td>Date 2</td><td>Date 3</td></tr>
    <tr><td>Date 4</td><td>Date 5</td><td>Date 6</td></tr>
    </tbody>
    </table>`
    this.dataTableInstance = helpers.createInstanceFromHTML({html: html, options: {order: [[0, 'asc']]}})
    console.log(order)
    expect(this.dataTableInstance.options.order).toBe(order);
  })

But when I run this the test fails and gives this output × table first column is in ascending order Expected [ [ 0, 'asc', _idx: 0 ] ] to be [ [ 0, 'asc' ] ]. Tip: To check for deep equality, use .toEqual() instead of .toBe().

It is referring to the column index which I have not set and can't seem to add to the order array anyway does anyone know where this comes from or why it is happening?

Additionally if I changed .toBe to .toEquals I would get a similar error about the _idx: 0 property any help is appreciated

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @gwar9 ,

    I used this in our tests:

    expect(table.order().toString()).toBe('0,asc');
    

    You could try the same,

    Cheers,

    Colin

  • gwar9gwar9 Posts: 2Questions: 1Answers: 0

    @colin thanks, that does seem to pass the test but is it actually evaluating the order of the column? I have limited exp writing tests so I'm not sure exactly whats happening when you convert to a string?

This discussion has been closed.