Support d3.drag in testing environments
penx opened this issue · comments
Alasdair McLeay commented
As per the report in #79 which was closed without a fix.
If using d3-drag in a non browser environment, such as jest + testing-library, an error will be thrown:
Error: Uncaught [TypeError: Cannot read property 'document' of null]
This comes from
Lines 50 to 63 in c6a7e46
Lines 4 to 5 in c6a7e46
Because view
is null.
Downstream issues:
I think nodrag should return early if view is null:
export default function(view) {
if(!view) {
return;
}
var root = view.document.documentElement,
selection = select(view).on("dragstart.drag", noevent, nonpassivecapture);
if ("onselectstart" in root) {
selection.on("selectstart.drag", noevent, nonpassivecapture);
} else {
root.__noselect = root.style.MozUserSelect;
root.style.MozUserSelect = "none";
}
}
...at least, this works for my use case. I'll raise a PR.