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

When using deepEqual the console output doesn't stringify the object #3591

Closed
reallymello opened this issue Jan 30, 2023 · 1 comment · Fixed by #3650
Closed

When using deepEqual the console output doesn't stringify the object #3591

reallymello opened this issue Jan 30, 2023 · 1 comment · Fixed by #3650

Comments

@reallymello
Copy link
Contributor

reallymello commented Jan 30, 2023

Description

When using the @nightwatch/apitesting plugin sometimes I will use deep equal (.eql) to save time comparing properties and values in a response object to my expectation. This works great when everything passes, but when there is a equality mismatch failure the console output returns something like

   – Can do a partial booking update (310ms)

   → ✖ NightwatchAssertError
   expected { firstname: 'Really', …(5) } to deeply equal { firstname: 'Really', …(5) } - expected "[object Object]" but got: "[object Object]" (1ms)

It would be great if instead of [object Object] there was a JSON.stringify done to output the actual contents so one could see what field(s) or value(s) caused the deep equal to fail (what the differences are)

Example test:

  'Can do a partial booking update': async ({
    supertest,
  }: NightwatchBrowser) => {
    await supertest
      .request(baseUrl)
      .patch(`/booking/${bookingId}`)
      .set('Content-type', 'application/json')
      .auth('admin', 'password123')
      .accept('application/json')
      .send({
        additionalneeds:
          'Unreasonable demands',
      })
      .expect(200)
      .then((response: any) => {
        // This is the assertion I've setup to fail by modifying the additionalneeds field from the original record and asserting agains the original values
        expect(response.body).eql(bookingData);
      });
  },

Suggested solution

Apply JSON.stringify or something similar to do a friendly print out of the object to allow people to see what the mismatch was or other functionality to help identify what is different when comparing objects.

Alternatives / Workarounds

No response

Additional Information

No response

@github-actions
Copy link

Thank you for setting this as an enhancement. One of the product folk will triage this again to help see when we can fit this in an upcoming sprint.

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

Successfully merging a pull request may close this issue.

4 participants