Giter VIP home page Giter VIP logo

Comments (11)

krzkaczor avatar krzkaczor commented on August 24, 2024 1

@all-contributors please add @krzysztof-jelski for ideas

from earl.

krzkaczor avatar krzkaczor commented on August 24, 2024

We already have expect.containerWith for iterables and we still need arrayWith and objectWith.

This is tracked in: #48 so I'll close this as a duplicate.

It will be done during the weekend by me but you can contribute it if you want earlier :-> It's a simple matcher and we have already similar ones.

from earl.

sz-piotr avatar sz-piotr commented on August 24, 2024

Why close this? The issue is about a validator, not a matcher (even though the name matcher is used)

from earl.

krzkaczor avatar krzkaczor commented on August 24, 2024

Uhh, I thought it's about matchers. Linking to our docs for completeness: https://earljs.dev/docs/introduction/core-concepts

Still, my thinking is that we don't need validators duplicating what can be easily achieved with existing validators + matchers. For example:

expect({a: 1, b: 2, c: 3}).toContainSubset({a: 1, c: 3})

Is the same as:

expect({a: 1, b: 2, c: 3}).toEqual(expect.objectWith({a: 1, c: 3}))

Matchers are in principle more powerful than validators as they can be used in many different contexts (for example in given of mocks) and they compose well.

I don't have a very strong opinion on this as I already saw with toThrow that it's not always a good idea to embrace matchers 😆 But if we decide to introduce these validators, their naming should be inlined with matchers to make it clear that it's a shorthand.

I'll reopen to discuss.

from earl.

sz-piotr avatar sz-piotr commented on August 24, 2024

Personally i believe it is good to have duplication in this particular case. Possibly also with expect.a we could have expect(x).toBeA validator.

All in all it comes down to the fact that the code should be the most descriptive, since the tests serve as specification. So it is more descriptive to write expect([1, 2]).toContain(1) than expect([1, 2]).toEqual(expect.arrayWith(1)). The second, while more powerful introduces a lot of noise, potentially leading to people thinking functionality like this is missing.

from earl.

krzkaczor avatar krzkaczor commented on August 24, 2024

Okay I agree that these validators would be handy indeed. Lets start with:

  • expect(x).toBeA(...) uses expect.a
  • expect(x).toBeContainerWith uses expect.containerWith
  • expect(x).toBeArrayWith uses expect.arrayWith
  • expect(x).toBeObjectWith uses expect.objectWith

Note: I renamed toContainSubset proposed by @krzysztof-jelski to something that goes well with the names that we picked for matchers.

Let me know if you have any naming suggestions.

from earl.

krzysztof-jelski avatar krzysztof-jelski commented on August 24, 2024

Yes, the naming looks perfect 👌

from earl.

krzysztof-jelski avatar krzysztof-jelski commented on August 24, 2024

Hmm perhaps grammar-wise we should add an indefinite article in each one, as in:

expect(x).toBeAnObjectWith

from earl.

krzkaczor avatar krzkaczor commented on August 24, 2024

Yeah, I wondered about this too. I will check how other libs go about it, after all, we don't have expect.a.objectWith() 🤷

from earl.

krzkaczor avatar krzkaczor commented on August 24, 2024

@sz-piotr do you have any opinions on naming here?

from earl.

sz-piotr avatar sz-piotr commented on August 24, 2024

I'd prefer something grammatically correct. So definitely toBeAContainerWith and toBeAnArrayWith over toBeContainerWith and toBeArrayWith. I'd also propose renaming toBeAContainerWith to toContain

from earl.

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.