Question: I have a list of objects which, depending on the condition that applies, has a variable type. However, I have not found a way to make this happen.

issue:
`cannot implicitly convert type List<TABLE_ONE> to type list<object>`

```
 List<object> listName;

    switch (sourceTableName)
    {
        case "TABLE_ONE":
            listName = m_api.Database.ExecuteQuery<TABLE_ONE>($"SELECT * FROM {sourceTableName}");
            break;
        case "TABLE_TWO":
            listName = m_api.Database.ExecuteQuery<TABLE_TWO>($"SELECT * FROM {sourceTableName}");
            break;
        case "TABLE_THREE":
            listName = m_api.Database.ExecuteQuery<TABLE_THREE>($"SELECT * FROM {sourceTableName}");
            break;
    }

foreach (var row in listName)
     {
        var dif3 = new DataInterfaceFactory(DatabaseTypes.SqlServer, row.DatabaseName, row.ServerName);
        do stuff...
     }

```

the variable `sourceTableName` is a string that contains the name of a class.

**Classes that are used as types:**

```
    public class TABLE_ONE
    {
        public int TableOneColumnUid;
        public string ServerName;
        public string DatabaseName;
        public DateTime LastCheckDate;
        public int IsRunning;
    }
    public class TABLE_TWO
    {
        public int TableTwoColumnUid;
        public string ServerName;
        public string DatabaseName;
        public DateTime LastCheckDate;
        public int IsRunning;
    }
    public class TABLE_THREE
    {
        public int TableThreeColumnUid;
        public string ServerName;
        public string DatabaseName;
        public DateTime LastCheckDate;
        public int IsRunning;
    }

```

Answer: 
I had to mock the implementation of my `onSubmit` function to clear the error, preventing the default submit behavior.

Give something like this a try:

```js
const onSubmit = jest.fn();

it("should invoke onSubmit when form is submitted", async () => {
      onSubmit.mockImplementation(event => {
        event.preventDefault();
      });

      const { getByText } = renderCard({ onSubmit });
      const button = getByText("Save").closest("button");
      if (button) {
        fireEvent.click(button);
      }
      await wait(() => expect(onSubmit).toHaveBeenCalled());
 });

```

You can read more about event.preventDefault in React [here](https://reactjs.org/docs/handling-events.html) and [here](https://www.robinwieruch.de/react-preventdefault).

Something else that worked for me was using RTL's `fireEvent.submit`, although you need to get a form element for that to work. Assuming your implementation of `Card` renders a form in a way that's recognizable by `getByRole`, you could also try something like this:

```js
fireEvent.submit(screen.getByRole('form'));

```

That would be in lieu of simulating the button click, which may be acceptable in your case since you seem to be testing form submission rather than the button's behavior.
I had also a similar issue.   

However, for me this was happening because I was using `userEvent.click` and the solution of placing `preventDefault()` in the `fn` didn't work for me since the click event and submit event are different. 
I had to switch to `fireEvent.submit` and that worked without the need to prevent default and be able to test the form submission.

PS: I was using a `form` to wrap the inputs

Error

```js
   import userEvent from "@testing-library/user-event";

```

Work

```js
   import {fireEvent} from '@testing-library/react';

```

This is the basic form implentation

```js
   <form onSubmit={handleSubmit}>
     <input type={'text'} placeholder={'user name'} value={username} onChange={e => setUsername(e.target.value)} />
     <br/>
     <input type={'text'} placeholder={'password'} value={password} onChange={e => setPassword(e.target.value)} />
     <br/>
     <input type={'submit'} disabled={!username && !password} value={'Login'} />
   </form>

```

And here you can see the implementation of the test to handle the submitted event

```js
it('should handle submit event', async () => {
    const handleSubmitFn = jest.fn();
    render(<Form handleSubmit={handleSubmitFn}/>);

    const username = screen.getByPlaceholderText(/user name/);
    const password= screen.getByPlaceholderText(/password/);
    const submitButton = screen.getByText(/login/i);

    userEvent.type(username, 'myuserbla');
    userEvent.type(password, 'mypwd');

    fireEvent.submit(submitButton)

    await waitFor(() => {
      expect(handleSubmitFn).toHaveBeenCalledTimes(1);
    })
  })

```