frontend-collective / frontend-collective/react-sortable-tree

Question: how do you mock this thing?

Open
#365 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
JavaScript
Stars
5k
Forks
914
PR merge metrics
No merged PRs in 30d

Description

I tried writing a test using the most basic SortableTree I could, the example in the docs with a chicken and egg. The test itself looks exactly like this:

```
import React from 'react'
import renderer from 'react-test-renderer'
import {MySortableTree} from '../components/MySortableTree'

describe('mySortableTree', function () {
it('should render some stuff', function () {
const myTree = renderer.create(

)
})
})
```

And I get a TypeError nested deeply in the library which looks like this:

TypeError: this.container.addEventListener is not a function
at ScrollingComponent.componentDidMount (node_modules/react-dnd-
scrollzone/lib/index.js:159:24)
/* lots more lines that are irrelevant */

The above error occurred in the component:
in Scrolling(List) (created by AutoSizer)
in div (created by AutoSizer)
in AutoSizer (created by ReactSortableTree)
in div (created by ReactSortableTree)
in ReactSortableTree (created by DragDropContext(ReactSortableTree))
in DragDropContext(ReactSortableTree) (at MySortableTree.js:17)
in div (at MySortableTree.js:16)
in MySortableTree (at testMySortableTree.js:8)

Now I'm a complete beginner with writing tests so I could have done something wrong, if you have a better way of mocking it let me know :)

PS: I first tried this with a much more complex SortableTree and got a very similar TypeError:

Cannot read property 'scrollLeft' of null
at Grid.componentDidMount
....
The above error occurred in the component:
in Scrolling(List) (created by AutoSizer)
in div (created by AutoSizer)
in AutoSizer (created by ReactSortableTree)
in div (created by ReactSortableTree)
....

PPS: Tried doing it with Enzyme.mount instead of renderer.create and got another TypeErrror:
Cannot read property 'getMonitor' of undefined at scrollingComponent.componentDidMount

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.