Coder Social home page Coder Social logo

Comments (7)

kfcampbell avatar kfcampbell commented on August 25, 2024 2

I think I have a weak preference in favor of jest.ToEqual. I had to remind myself of the differences when looking at .toStrictEqual docs:

  • keys with undefined properties are checked, e.g. {a: undefined, b: 2} will not equal {b: 2};
  • undefined items are taken into account, e.g. [2] will not equal [2, undefined];
  • array sparseness is checked, e.g. [, 1] will not equal [undefined, 1];
  • object types are checked, e.g. a class instance with fields a and b will not equal a literal object with fields a and b.

None of those seem deal-breaking to me, though I'd be interested to hear others' thoughts.

from core.js.

gr2m avatar gr2m commented on August 25, 2024 1

Thumbs up reaction (👍🏽) for jest.ToEqual, and I can apply the changes here:

👍🏼 from me, thank you @oscard0m for taking on this and other chore tasks 💛

from core.js.

oscard0m avatar oscard0m commented on August 25, 2024

I took a look into it.

The toStrictEqual is doing some customTesters internally. The one giving problems is typeEquality. Concretely, this comparison: a.constructor === b.constructor.

When using fetch-mock, the accepted type for response parameter in getOnce(matcher, response) are:

type MockResponse = Response | Promise<Response>
                        | number | Promise<number>
                        | string | Promise<string>
                        | {} | Promise<{}>
                        | MockResponseObject | Promise<MockResponseObject>;

According to this code comment:

  • object: As long as the object is not a MockResponseObject it is
    * converted into a json string and returned as the body of a 200 response

This means the constructor equal comparison is lost at this point.12

Considering these are mocks controlled by ourselves, the alternatives I come up with are:
a) to use a jest.toEqual
b) to keep the hack of JSON.stringify
c) try if passing a MockResponseObject or Response gets the right constructor and toStrictEqual works.

What do you think @octokit/extensibility-sdks @octokit/js-community ?

Footnotes

  1. https://github.com/gr2m/fetch-mock/blob/1bdac54e1b482398cca0af9658a500de23e72367/src/lib/fetch-handler.js#L268-L278

  2. https://github.com/gr2m/fetch-mock/blob/1bdac54e1b482398cca0af9658a500de23e72367/src/lib/response-builder.js#L113

from core.js.

oscard0m avatar oscard0m commented on August 25, 2024

Thumbs up reaction (👍🏽) for jest.ToEqual, and I can apply the changes here:

from core.js.

wolfy1339 avatar wolfy1339 commented on August 25, 2024

There is at least one case where I switched to toMatchObject()

Those could probably be updated as well

from core.js.

oscard0m avatar oscard0m commented on August 25, 2024

There is at least one case where I switched to toMatchObject()

Those could probably be updated as well

In a quick search these are the ones I found:

The rest can be progressively updated. It's not a problem to have jest.toMatchObject().

from core.js.

oscard0m avatar oscard0m commented on August 25, 2024

Thank you all for the quick reviews. We are done with this. 🥳 🎆 🍾

from core.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.