Comments (4)
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.
@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.
Currently the noted techniques for what you are asking will work with stateful classes extending Component
.
from preact-render-spy.
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)
- first() and last() functions for FindWrapper
- children and childAt functions for FindWrapper
- reduce() function for FindWrapper HOT 2
- exists function for FindWrapper
- .output() API Naming Bikeshed HOT 8
- Separate FindWrapper core and extended methods HOT 5
- Deprecate `childAt` HOT 3
- Is there any way to simulate keydown events? HOT 3
- Shallow or Deep can't compile the app when async module are loaded HOT 2
- index.d.ts is missing a number of type signatures HOT 1
- .text() behaviour for input elements HOT 1
- setting a defaultProps property on a component breaks the nodeName property of RenderContext HOT 1
- Are components valid selectors?
- defaultProps not working correctly with functional components HOT 1
- Testing with HOC and shallow HOT 2
- .find by data-attributes HOT 3
- Receiving function prop as undefined
- TypeError: this.contextRender is not a function when using shallow HOT 1
- Is project going to support preact 10? HOT 9
- Issue with `.attr()`: Argument not assignable to parameter of type 'never' 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 preact-render-spy.