Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receiving function prop as undefined #86

Open
rafaellages-hotmart opened this issue Jan 10, 2019 · 0 comments
Open

Receiving function prop as undefined #86

rafaellages-hotmart opened this issue Jan 10, 2019 · 0 comments

Comments

@rafaellages-hotmart
Copy link

Hi guys Im having a weird problem where my component receive a function parameter as undefined if:
It is not declared in the same scope
OR
I don't declare and pass other variables on the same scope

describe('myTest', () => {
  let myComponent
  let myMock

  beforeEach(() => {
    myMock = jest.fn()
    myComponent = shallow(
      <MyComponent action={myMock} />
    )
  })
})

FAIL this.props.action is undefined

describe('myTest', () => {
  let myComponent

  beforeEach(() => {
    let myMock = jest.fn() // declared on the same block
    myComponent = shallow(
      <MyComponent action={myMock} />
    )
  })
})

WORKS this.props.action is my mock

describe('myTest', () => {
  let myComponent
  let myMock

  beforeEach(() => {
    myMock = jest.fn()
	let anything = 'anything' // anything else declared and passed in the same block
    myComponent = shallow(
      <MyComponent action={myMock} anything={anything}/>
    )
  })
})

WORKS this.props.action is my mock

my deps:

{
"jest": "^23.6.0",
"preact-cli": "^2.2.1",
"preact-render-spy": "^1.3.0",
"preact": "^8.4.2"
}

any ideas?
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant