sarink / react-file-drop

React component for Gmail or Facebook -like drag and drop file uploader

Home Page:https://www.sarink.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unit testing the components using FileDrop

whiteadi opened this issue · comments

Hi,

I try to create a test with enzyme for rendering a component using FileDrop.

import { shallow } from 'enzyme'
import expect from 'expect'
import React from 'react'
import SomeInput from './SomeInput.jsx'

describe('Component: SomeInput', () => {
  it('should render self and subcomponents', () => {
    const wrapper = shallow(<SomeInput />)
    expect(wrapper.props().className).toBe('someInput')
    expect(wrapper.find(<textarea />).length).toBe(1)
  })
})

I got:

Test suite failed to run

ReferenceError: document is not defined

at
import FileDrop from 'react-file-drop'

at Function.getDefaultProps (node_modules/react-file-drop/FileDrop.js:44:24)
      at createClass (node_modules/create-react-class/factory.js:869:46)
      at node_modules/react-file-drop/FileDrop.js:18:20
      at Object.<anonymous>.createReactClass.displayName (node_modules/react-file-drop/FileDrop.js:6:26)
      at Object.<anonymous> (node_modules/react-file-drop/FileDrop.js:16:2)
      at Object.<anonymous> (src/components/chat/someInput/someInput.jsx:8:22)

there at line 44 is the frame...

getDefaultProps: function () {
            return {
                dropEffect: "copy",
                frame: document,
                targetAlwaysVisible: false
            };
        },

can you please have that document be an empty object if no global document exists, or any solution because I really do not want to use jDom.

Can you just declare a global variable const document = {} in the setup section of that test?

Maybe would be nice if you read what I took the time to write :)
It still does not work because it fails at importing the component that contains the import of FileDrop,
so at import FileDrop from 'react-file-drop', and the import executes ""before setup of that test.
I actually tried it, also I tried it in the stup for all tests still does not work.

I'm really unsure how you expect this can be fixed by the library? We can't redefine document?