educative.io

Final code does not match explanation

Final code does not match, and I can’t figure how this: "const promise = Promise.reject();

axios.get.mockImplementationOnce(() => promise);

let component;

await renderer.act(async () => {
  component = renderer.create(<App />);
});" actually changes the test component

Hi @Stuart_Strom
The following code is used for mocking the response from the remote API by mocking the method that fetches the data. To stay on the happy path, we told the test to treat the component as an asynchronously updating component. You can apply a similar strategy to the unhappy path.
We moved from focused unit tests for single components to tests with multiple components and their integration with third parties like Axios and remote APIs.

Secondly, the Promise. reject() method is used to return a rejected Promise object with a given reason for rejection. It is used for debugging purposes and selective error catching.

Hope it will clear your confusion, Happy Learning :slight_smile:

1 Like