react icon indicating copy to clipboard operation
react copied to clipboard

Unknown prop warning on allowed props

Open bsr203 opened this issue 10 years ago • 12 comments

In some of my jest (snapshot) test, I see this warning.

Running 4 test suites...Warning: Unknown prop className on <div> tag. Remove this prop from the element. For details, see https..../react-unknown-prop
    in div (created by Container)

but, className is how react set the class attribute. I do understand the change brought by react 15.0.2, but not sure why getting this for className.

I get same warning for more attributes

Running 1 test suite...Warning: Unknown prop className on <div> tag. Remove this prop from the element. For details, see https://fb.me/react-unknown-prop
    in div (created by Container)
    in Container (created by ..)
    ...
    in Unknown
Warning: Unknown props role, autoComplete, noValidate, onSubmit on <form> tag. Remove these props from the element. For details, see https://fb.me/react-unknown-prop
    in form (created by Form)
    in div (created by Card)
    ...
    in Unknown
Warning: Unknown props name, type, value, onChange on <input> tag. Remove these props from the element. For details, see https://fb.me/react-unknown-prop
    in input (created by Input)

I use jest 14.1.0 and react 15.3.1.

bsr203 avatar Aug 29 '16 00:08 bsr203

Can you share your component/test case that's getting these warnings? Or better yet, a repo reproducing this

aweary avatar Aug 29 '16 04:08 aweary

I am also getting this. I'll try to get a test repo later today. Also getting:

Warning: Unknown prop `onClick` on <li> tag. ...

Xesued avatar Aug 29 '16 12:08 Xesued

Same issue here.

Jest output:

 PASS  __tests__/integration.spec.js
  ● Console

    console.error node_modules/fbjs/lib/warning.js:36
      Warning: Unknown prop `className` on <div> tag. Remove this prop from the element. For details, see https://fb.me/react-unknown-prop
          in div (created by App)
          in App
          in Provider

Simplified repro...

App.jsx:

export default class App extends Component {
  render() {
    return (<div className="foo">bar</div>)
  }
}

integration.spec.js:

import React from 'react'
import {Provider} from 'react-redux'
import renderer from 'react-test-renderer'
import {applyMiddleware, createStore} from 'redux'
import thunk from 'redux-thunk'

import App from '../components/App'
import rootReducer from '../reducers'

jest.mock('react/lib/ReactDefaultInjection')

const store = createStore(rootReducer, {}, applyMiddleware(thunk))

describe('foo', () => {
  it('bar', () => {
    const component = renderer.create(
      <Provider store={store}>
        <App />
      </Provider>
    )
    expect(component.toJSON()).toMatchSnapshot()
  })
})

tonygentilcore avatar Sep 04 '16 22:09 tonygentilcore

Thanks @tonygentilcore, I'll try and reproduce. Why are you mocking ReactDefaultInjection?

aweary avatar Sep 04 '16 23:09 aweary

That seems suspicious, doesn't it. It was suggested in some SO post or GH issue as a workaround for the following. If I remove it, the test spits:

 FAIL  __tests__/integration.spec.js
  ● Test suite failed to run

    Invariant Violation: ReactCompositeComponent: injectEnvironment() can only be called once.

      at invariant (node_modules/fbjs/lib/invariant.js:38:15)
      at Object.ReactComponentEnvironment.injection.injectEnvironment (node_modules/react/lib/ReactComponentEnvironment.js:36:60)
      at Object.inject (node_modules/react/lib/ReactDefaultInjection.js:79:28)
      at Object.<anonymous> (node_modules/react/lib/ReactDOM.js:28:23)
      at Object.<anonymous> (node_modules/react-dom/index.js:3:18)
      at Object.<anonymous> (node_modules/draft-js/lib/DraftEditorTextNode.react.js:23:16)
      at Object.<anonymous> (node_modules/draft-js/lib/DraftEditorLeaf.react.js:24:27)
      at Object.<anonymous> (node_modules/draft-js/lib/DraftEditorBlock.react.js:27:23)
      at Object.<anonymous> (node_modules/draft-js/lib/DraftEditorContents.react.js:26:24)
      at Object.<anonymous> (node_modules/draft-js/lib/DraftEditor.react.js:29:27)
      at Object.<anonymous> (node_modules/draft-js/lib/Draft.js:22:19)
      at Object.<anonymous> (reducers/ui.js:1:232)
      at Object.<anonymous> (reducers/index.js:5:37)
      at Object.<anonymous> (__tests__/integration.spec.js:23:1018)
      at process._tickCallback (internal/process/next_tick.js:103:7)

tonygentilcore avatar Sep 04 '16 23:09 tonygentilcore

@tonygentilcore check out https://github.com/facebook/react/issues/7386, that's expected behavior at the moment. You can't use react-test-renderer with another library that uses react-dom, as they both try to call injectEnvironment. This will be resolved in the 15.4 release 👍

Are you able to reproduce the unknown prop warning at all without mocking ReactDefaultInjection? You'd have to test with components that do not use react-dom.

It was suggested in some SO post or GH issue as a workaround for the following

I have a feeling that is likely what's causing this issue. If you know where you saw that recommendation I'd be super interested in knowing.

aweary avatar Sep 05 '16 00:09 aweary

@bsr203 @Xesued were you guys using the same workaround?

aweary avatar Sep 05 '16 00:09 aweary

Yes. I too use the workaround. I came to know about it through the recommendtations in this issue https://github.com/facebook/jest/issues/1353

I guess we have to tolerate this warning till 15.4.0

bsr203 avatar Sep 05 '16 00:09 bsr203

Yes. I was.

On Sep 4, 2016 7:25 PM, "bsr203" [email protected] wrote:

Yes. I too use the workaround. I came to know about it through the recommendtations in this issue facebook/jest#1353 https://github.com/facebook/jest/issues/1353

I guess we have to tolerate this warning till 15.4.0

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/facebook/react/issues/7601#issuecomment-244637235, or mute the thread https://github.com/notifications/unsubscribe-auth/ABF8RXPKMyTfLTWyHaBPGo7-wh1hUw9Oks5qm2GTgaJpZM4JvELq .

Xesued avatar Sep 05 '16 00:09 Xesued

Thanks guys, I'm going to close this out for now since 15.4 will resolve the root cause and this workaround isnt really recommended.

aweary avatar Sep 05 '16 01:09 aweary

@Aweary I see a new rc at npm

latest: 15.3.1
next: 15.3.2-rc.1

I do not see a 15.4 branch and not sure the fix is already in master or 15.3.2-rc.1. Can you please comment whether the fix is in 15.3.2-rc.1, else available at master?

bsr203 avatar Sep 16 '16 16:09 bsr203

The issue with injectEnvironment was fixed in React 15.4.0 which is out today. If you were mocking ReactDefaultInjection (which is unsupported) please remove those changes, and it will work.

gaearon avatar Nov 16 '16 15:11 gaearon