mzgoddard / preact-render-spy

Render preact components with access to the produced virtual dom for testing.

Home Page:https://www.npmjs.com/package/preact-render-spy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Documentation for running on node

peterjwest opened this issue · comments

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!

@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

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

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

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

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

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

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?