react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

`onCompleted` does not receive mocked data from MockedProvider

Open KonradKlimczak opened this issue 4 years ago • 6 comments

Data from mocked result in MockProvider is not passed to onCompleted callback.

I have component like this:

function Dogs({ onDogSelected }) {
  const [options, setOptions] = useState([]);
  const [fetch, { loading, error }] = useLazyQuery(GET_DOGS, {
    onCompleted: (data) => {
      setOptions(data.dogs);
    }
  });

  if (loading) return 'Loading...';
  if (error) return `Error! ${error.message}`;

  useEffect(() => {
    fetch();
  }

  return (
    <select name="dog" onChange={onDogSelected}>
      {options.map(dog => (
        <option key={dog.id} value={dog.breed}>
          {dog.breed}
        </option>
      ))}
    </select>
  );
}

When I create a test and wrap it with MockProvider which has mocked query for this component, in onCompleted callback I receive undefined instead of data. If I use it in default way using returned data from useLazyQuery it works just fine.

KonradKlimczak avatar Mar 24 '20 15:03 KonradKlimczak

I am also facing the same issue...Any help is much appreciated

deepubohra avatar Apr 16 '20 10:04 deepubohra

Same here!

carlespibernat avatar May 07 '20 15:05 carlespibernat

bump

wildantokped avatar May 12 '20 01:05 wildantokped

I seem to have just run into the same issue. Did anyone find a way around this?

smehltrett avatar Jun 16 '20 18:06 smehltrett

Any news or workaround?

yuriburk avatar Jul 07 '20 01:07 yuriburk

Was writing tests & got stuck on this, the data received on onCompleted is always undefined

essaji avatar Jul 16 '20 08:07 essaji