Git Product home page Git Product logo

Comments (4)

gnarf avatar gnarf commented on June 8, 2024 3

In your usecase, the document fragment we use is stored in context.fragment this should be what you are looking for.

It's undocumented, but that could change.

One thing, with a shallow render, any component/stateless function children will not have any representation in the DOM, we replace them with null nodes during the render, so you won't have any representation of those children in the DOM iteself.

try some of these and let me know if we already have the solution but just need some documentation:

const context = shallow(<Testable />);
console.log(context.fragment);
// we also have our own toString that does a shallow render:
console.log(context.toString());
// if using jest you could even use our snapshot plugin (read docs)
expect(context).toMatchSnapshot();

from preact-render-spy.

mzgoddard avatar mzgoddard commented on June 8, 2024 1

@joshuataylor Since its preact. You could get the DOM with context.component().base. preact stores the component's dom element at the .base member. You could get the html as a string with context.component().base.outerHTML I think (or .innerHTML if you want that). That'll be up to the support of your DOM environment. (Testing with a browser through selenium, karma, etc, would obviously work. I'd figure jsdom should support that as well, but I don't personally know.)

I think the best place right now for tips like this would be in our examples section or in a related adjacent section.

from preact-render-spy.

mzgoddard avatar mzgoddard commented on June 8, 2024

Currently the noted techniques for what you are asking will work with stateful classes extending Component.

from preact-render-spy.

joshuataylor avatar joshuataylor commented on June 8, 2024

Sorry for the delay in getting back! Yes, context.fragment is perfect and returns what I need. Will see if I can write some documentation with my experiences, preact-render-spy makes things so much easier.

from preact-render-spy.

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.