Comments (16)
@goatslacker when you build a chai plugin, it automatically adds them for all three of its APIs: expect
, should
and assert
from enzyme.
I assume to.have.all.props
and to.have.any.props
could be supported as well? also, expect(wrapper).to.contain(foo)
/ expect(wrapper).not.to.contain(foo)
, and expect(wrapper).to.be(Foo)
/ expect(wrapper).not.to.be(Foo)
.
from enzyme.
yes. excellent! We should get a list of the desired extensions and implement...
from enzyme.
Hello! I am currently working on an enzyme-chai framework. I call it chai-shallowly
!
Currently the API looks like this:
it("should render the correct type", () => {
expect(component).to.shallowly.match("span");
});
it("should set default classes on the element", () => {
expect(component).to.shallowly.haveClass("prod-ProductHelpFlyoutButton inline-block-xs");
});
it("should render the correct type of children", () => {
expect(component).to.shallowly.haveComponent(Flyout);
});
I am likely going to spin this in to its own repo though, not inside reagent.
What do you think?
from enzyme.
How about also having one with a better API like assert
?
from enzyme.
Well that's badass. TIL
from enzyme.
@goatslacker what said @lelandrichardson is correct. Some of what I am doing is name spacing (e.g. haveClass
vs .have.class
). I'm working only on porting over shallow
rendered portion.
from enzyme.
chai.js core dev here.
here at product hunt, we've built an internal project, quite similar to enzyme, and we are now looking to migrate.
we already have custom chai.js assertions for our internal project, and porting those for enzyme will be quite straight forward.
if you are interested in a collaboration, let me know.
edit: some assertions we use
to.have.tagName
to.have.html
to.have.style
to.have.text
to.have.value
to.have.css
to.have.attr
to.have.props
to.have.component().with.props()
most of the stuff from https://github.com/chaijs/chai-jquery is applicable too
from enzyme.
We are currently working on moving this from internal testing to external
open source. There are just a few more improvements we will need to make.
I'll keep you updated.
from enzyme.
@vesln that sounds awesome! As you migrate the chai matchers, could you ensure that none of them end in properties, ie, they all require a terminal function invocation?
from enzyme.
All, we just open sourced our chai.js assertions for enzyme. Feedback/prs/feature requests/issues are very welcome!
@ljharb lmk if you are ok with including it in the docs so more people can discover and leverage it.
I'll update chai.js's website later this week as well.
from enzyme.
@vesln awesome! The only issues I see are to.be.empty
and to.exist
- our styleguide's eslint plugin prohibits these (noop expressions) and airbnb/javascript#646 and #97 (comment) talk a bit more about why they should be avoided. Should I file an issue on chai-enzyme
directly?
Otherwise, a PR would be welcome to add it to the docs :-)
from enzyme.
@ljharb the issue is that those methods are already getters in chai.js itself and we cannot redefine them.
what i can do tho is alias them to .to.be.blank()
and .to.be.present()
. sounds good?
from enzyme.
sure, that sounds awesome - i have no objection to mentioning exist/empty in the chai-enzyme docs either, as long as there's alternatives :-)
from enzyme.
π
from enzyme.
Closing as there is now: https://github.com/producthunt/chai-enzyme
from enzyme.
Related Issues (20)
- enzyme-adapter-react-18 HOT 2
- Component is not re-rendered with updated states HOT 5
- Cheerio 1.0.0-rc.11 no longer support deep imports HOT 3
- enzyme crash since Cheerio 1.0.0-rc.11 release HOT 5
- CSS selectors match component props rather than rendered DOM HOT 6
- Cannot read property 'child' of undefined on React 16 + enzyme-adapter-react-16 HOT 1
- Cannot read property 'child' of undefined enzyme-adapter-react-16 and react 17.0.2 HOT 3
- "TypeError: Cannot read properties of undefined (reading 'current')" in mount API HOT 7
- Method βpropsβ is only meant to be run on a single node. 0 found instead. HOT 1
- How to test the form which is rendered based on props in class component in react.js ? HOT 3
- How to test the state values which are setting the state from local storage inside componentDidMount in enzyme using reactjs ? HOT 5
- Function `mount` does not mock proper data HOT 5
- [email protected] does not include latest changes as per master HOT 5
- Document `getElement(s)` for full DOM rendering HOT 3
- TypeError: window.require is not a function HOT 5
- Does Enzyme support React 18.0.2 ? HOT 1
- Is this library 'dead'? HOT 5
- Explain how the synchronization works HOT 1
- Mount and simulate are failing after changing to Node 16 HOT 10
- enzyme-adapter-react-18 HOT 1
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 enzyme.