GithubHelp home page GithubHelp logo

Comments (10)

lelandrichardson avatar lelandrichardson commented on April 28, 2024 2

@laurakelly context support is now available on enzyme v1.2.0

from enzyme.

bscherminator avatar bscherminator commented on April 28, 2024 1

@lelandrichardson How does one mock getBoundingClientRect using the options?

from enzyme.

lelandrichardson avatar lelandrichardson commented on April 28, 2024

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.

blainekasten avatar blainekasten commented on April 28, 2024

That is the same API, TestUtils.shallowRenderer().render uses. So I would second that and stay consist when possible. πŸ‘

from enzyme.

lelandrichardson avatar lelandrichardson commented on April 28, 2024

@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.

blainekasten avatar blainekasten commented on April 28, 2024

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.

lelandrichardson avatar lelandrichardson commented on April 28, 2024

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.

laurakelly avatar laurakelly commented on April 28, 2024

@lelandrichardson Great, thank you! I'll try it out

from enzyme.

havenchyk avatar havenchyk commented on April 28, 2024

@lelandrichardson well, it looks like {attach: true} doesn't work for me with getBoundingClientRect

from enzyme.

lelandrichardson avatar lelandrichardson commented on April 28, 2024

@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)

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.