Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading error message when .roughly() assert fails #11

Open
kiprobinsonknack opened this issue Dec 19, 2022 · 0 comments
Open

Misleading error message when .roughly() assert fails #11

kiprobinsonknack opened this issue Dec 19, 2022 · 0 comments

Comments

@kiprobinsonknack
Copy link

When using .roughly(), when a test (legitimately) fails, the error message is misleading. Here is an example:

const chai = require('chai');

const { expect } = chai;
chai.use(require('chai-roughly'));

describe('example test set', () => {
  it('example test', () => {
    const expected = { num1: 12.39197,   num2: 5, num3: 19 };
    const actual =   { num1: 12.3919725, num2: 5, num3: 17 };
    expect(actual).to.roughly(0.001).deep.equal(expected); // fails (which is correct)
  });

});

The issue isn't that the test fails. The issue is that the failure message looks like this:

      AssertionError: expected { num1: 12.3919725, num2: 5, num3: 17 } to roughly deeply equal { num1: 12.39197, num2: 5, num3: 19 }
      + expected - actual

       {
      -  "num1": 12.3919725
      +  "num1": 12.39197
         "num2": 5
      -  "num3": 17
      +  "num3": 19
       }

image

This makes it look like the different values for num1 are also part of the reason why it failed, but the only reason it failed is that the num3 values are not within range. If you edit the num3 values to match, the test no longer fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant