GithubHelp home page GithubHelp logo

Comments (5)

marcodejongh avatar marcodejongh commented on June 9, 2024 1

You could write a assertion with descendants because it accepts a enzyme selector. I think the following would work:

const actual = expect(<MyComponent {...{ adminPath }}).to.have.descendants({ href: adminPath });

Although I'm not sure if href is a key or property in this case. It will only work for properties.

Besides that, if you want to do any kind of sane UI testing with Selenium you're gonna be adding those same id's & classes that would have made this unit tests easier to write. In the end the team should write testable code, having good identifiers on the elements you want to test later on is part of that.

from chai-enzyme.

ljharb avatar ljharb commented on June 9, 2024

Any reason expect(actual).toHaveNodeWithAttr('href', adminPath) and expect(actual).not.toHaveNodeWithAttr('href', adminPath) couldn't work by adding a single invertable assertion to chai-enzyme? (altho toHaveNodeWithProp might make more sense)

from chai-enzyme.

robwise avatar robwise commented on June 9, 2024

@ljharb That seems like a good way to go as well!

@marcodejongh Whoa, this is definitely useful. I didn't think of writing it that way. Thanks! And if you and your team see no reason not to use ids to make tests easier to write, maybe I should get my team to re-think our policy. I can definitely see how much easier these tests would be if we could just do find('#someId').

from chai-enzyme.

marcodejongh avatar marcodejongh commented on June 9, 2024

@robwise I think something along the lines of @ljharb's proposal would work. But it's only delaying the inevitable, unless you're absolutely sure you never want to UI test.

from chai-enzyme.

alex35mil avatar alex35mil commented on June 9, 2024

My only issue with ids is that we're going back to the problem which was just solved by CSS Modules: you need to think about uniqueness of ids.

  1. It's not a problem in context of component-oriented js unit testing, but it's not standard compliant in context of document (ok, I'm a bit pedantic here, but there is # 2).
  2. If you're using it in unit testing, you'll be using it in integration testing, and here we have a real problem.

from chai-enzyme.

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.