shichongrui / react-native-test-utils

A test utils library for testing react native components

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`createApi()` methods return cached values of component

phillbaker opened this issue · comments

After rendering a component, I believe that the component api text() function and props property are returning cached values of the rendered component's values because this line calls toJSON():

...createApi(view.toJSON())

Example:

test('it has the correct text', () => {
  let view = renderer(<MyComponent />)

  expect(view.text()).toContain('Hello') // passes

  let textInputView = view.query("TextInput[placeholder='Name']")
  textInputView.simulate('changeText', 'react-native-test-utils')

  expect(view.text()).toContain('react-native-test-utils') // fails
})

Proposed fix: pass a reference to the view and call toJSON() in the functions themselves.

That's a great catch. I'll do some digging to see if this is the culprit and see if we can fix it.