mzgoddard / preact-render-spy

Render preact components with access to the produced virtual dom for testing.
https://www.npmjs.com/package/preact-render-spy
ISC License
178 stars 24 forks source link

Documentation for running on node #48

Open peterjwest opened 7 years ago

peterjwest commented 7 years ago

Can you add documentation for running on node?

I am currently using a hack found in a closed issue:

import 'undom/register';

global['document'].createDocumentFragment = () => global['document'].createElement('#fragment');

Hopefully there's a way to do this without messing with global objects!

gnarf commented 7 years ago

@peterjwest the recently released 1.1.0 version should allow you to do:

import undom from 'undom';
import {config as renderSpyConfig} from 'preact-render-spy';
renderSpyConfig.createFragment = () => undom().body;

This is documented here:

https://github.com/mzgoddard/preact-render-spy#configuration

I would be open to a PR making a change to the README with an example

developit commented 7 years ago
import undom from 'undom';
import {config as renderSpyConfig} from 'preact-render-spy';
let doc = undom();
renderSpyConfig.createFragment = () => doc.createElement('body');
gnarf commented 7 years ago

@developit would createElement('#fragment') be better/worse?

peterjwest commented 7 years ago

Ace, thanks! I will be trying this out in the next few days.

gnarf commented 7 years ago

@peterjwest got any feedback, how do you think we should document this?

peterjwest commented 7 years ago

Not yet, sorry! I will try to have a look tonight.

peterjwest commented 6 years ago

Okay, so this seems to be the most sensible/minimal setup:

import 'undom/register';
import { config } from 'preact-render-spy';
config.createFragment = () => document.createElement('body');

Although I'm not sure where the #fragment came from, maybe that's more appropriate?