Comments (10)
@laurakelly context support is now available on enzyme v1.2.0
from enzyme.
@lelandrichardson How does one mock getBoundingClientRect
using the options?
from enzyme.
I think this would be a great addition! The only remaining question is what the right API is.
I propose that we add a second argument to mount
, shallow
, and render
which is simply an object named options
in order to be most flexible with future changes.
options
could have a context
property that, if defined, would be passed in as context to the parent component.
const context = { router: mockReactRouter() };
const wrapper = shallow(<MyComponent />, { context });
// ...
cc @ljharb @goatslacker thoughts?
from enzyme.
That is the same API, TestUtils.shallowRenderer().render
uses. So I would second that and stay consist when possible. π
from enzyme.
@blainekasten to be clear, I'm recommending that on object hash with a context
prop be passed in as a second argument to shallow
and the like, NOT that the context object itself be the second argument. The latter, I believe, is the current API for the shallowRenderer
from enzyme.
My bad. Why that approach? What other keys would be used and why?
On Sun, Dec 6, 2015 at 3:04 PM Leland Richardson [email protected]
wrote:
@blainekasten https://github.com/blainekasten to be clear, I'm
recommending that on object hash with a context prop be passed in as a
second argument to shallow and the like, NOT that the context object
itself be the second argument. The latter, I believe, is the current API
for the shallowRendererβ
Reply to this email directly or view it on GitHub
#49 (comment).
from enzyme.
My thinking is that it allows other "options" be passed in as well in the future, rather than just having a bunch of arguments at random slots of the function signature.
One such thing we discussed internally was the ability to have an option for mount
which indicated the node it mounts onto actually be attached to the document body:
const wrapper = mount(<Foo />, { attach: true });
Which could come in handy if you're wanting to test a component that uses DOM api's such as elem.getBoundingClientRect();
that require the DOM nodes be attached to a document.
from enzyme.
@lelandrichardson Great, thank you! I'll try it out
from enzyme.
@lelandrichardson well, it looks like {attach: true}
doesn't work for me with getBoundingClientRect
from enzyme.
@bscherminator what environment are you using getBoundingClientRect
in?
getBoundingClientRect
will always return a zero'd out rectangle if you're using jsdom. This will only work in something like karma with a browser runner
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.