GithubHelp home page GithubHelp logo

Problem using redux form about cavy HOT 4 CLOSED

FR98 avatar FR98 commented on June 15, 2024
Problem using redux form

from cavy.

Comments (4)

AbigailMcP avatar AbigailMcP commented on June 15, 2024 1

Ah I see! Sorry, I'm unfamiliar with how Redux Form works.

I've taken a closer look and think I have a solution - you're almost there!

In your form component:

<Field name="email" cavyName='LoginScreen.Username' component={RenderInput} />
<Field name="name" cavyName='LoginScreen.Password' component={RenderInput} />

In your RenderInput component:

export default function RenderInput({ input, cavyName }) {
  const generateTestHook = useCavy();
  const TestableTextInput = wrap(TextInput);

  return( 
    <TestableTextInput {...input} ref={generateTestHook(cavyName)}/>
  )
}

and in your tests:

spec.it('Success Index', async function() {
  ...
  const username = await spec.findComponent('LoginScreen.Username');
  usernameInput.props.onChange('abigail');

  const password = await spec.findComponent('LoginScreen.Password');
  passwordInput.props.onChange('mypassword');
});

Running these tests with this code works for me :)

Compared to your solution, there were two things I needed to change to get this to work due to how Redux Form is rendering it's components:

  1. Wrapping the input component (see these docs).
  2. Not using fillIn - when I inspected the components returned in the test using findComponent, I could see that onChangeText was not included in its props (which is what fillIn uses under the hood). However, I saw that there was an onChange prop that I could call directly! (see these docs).

from cavy.

AbigailMcP avatar AbigailMcP commented on June 15, 2024

Hi @FR98 ! Have you tried adding the generateTestHook ref to the inner <TextInput> instead of the <Field> component? Cavy needs a reference to the component with the onChangeText prop for fillIn to work.

from cavy.

FR98 avatar FR98 commented on June 15, 2024

Hi @AbigailMcP , thanks for your response... I can't do that because I use the <Field> component in others input fields at the same time (username and password) so I cannot define the generateTestHook ref in the inner <TextInput>. So I tried through pass the ref but it doesn't work as I spected and then I tried to define the generateTestHook ref in the <Field> dynamicaly by passing the name but it doesnt work... I dont know why (I think it should work) :(

Screenshot from 2020-09-29 23-10-45

Screenshot from 2020-09-29 23-10-27

Screenshot from 2020-09-29 23-11-00

So... I think the solution is to through pass the ref from the <Field> to the inner <TextInput>, but I could not. Do you have any idea?

from cavy.

FR98 avatar FR98 commented on June 15, 2024

Oh, it works! Thank you so much!

from cavy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.