Comments (5)
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.
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.
@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 id
s 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.
@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.
My only issue with id
s is that we're going back to the problem which was just solved by CSS Modules: you need to think about uniqueness of id
s.
- 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). - 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)
- [1.0.0-beta.0] Cannot assert descendant not present HOT 2
- Use of reserved word 'let' in strict mode HOT 3
- [1.0.0-beta.0] className assertion failing when element has multiple classNames HOT 10
- CLOSED: Dependency issues with new version of enzyme HOT 4
- React 15.0.0 and Enzyme 3.2.0 issue HOT 3
- Cannot find module 'enzyme/build/react-compat' HOT 4
- Cannot convert a Symbol value to a string
- to.have.text(undefined) does not break the tests
- Error message for shallow render contains HOT 4
- Patch version bump for fix merged in from PR#215? HOT 2
- Is this library still maintained? `[import Adapter from 'enzyme-adapter-react-15';]` HOT 5
- .should.have.html(...) broken in 1.0.0-beta.1
- .to.have.style() requires kebab-cased keys
- TypeError: to.have.style is not a function HOT 1
- setup is vague
- Flow types HOT 1
- Preact support? HOT 3
- Chai's `assert.` style supported ? HOT 2
- Cannot read property 'have' of undefined
- Support for React 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chai-enzyme.