Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

@apollo/react-testing will always raise an error when using newData #3455

Closed
zombiezen opened this issue Sep 4, 2019 · 2 comments
Closed

Comments

@zombiezen
Copy link

tl;dr: I believe these lines are wrong:

const { result, error, delay, newData } = response;
if (newData) {
response.result = newData();
this.mockedResponsesByKey[key].push(response);
}
if (!result && !error) {
throw new Error(
`Mocked response should contain either result or error: ${key}`
);
}

IIUC the assignment on line 90 should be moved to after the if (newData) conditional.

Intended outcome:

Use the newData function in a MockLink response.

Actual outcome:

Error thrown: Mocked response should contain either result or error

How to reproduce the issue:

Try to mock a response with:

const fakeData = [
  {
    request: {query: QUERY},
    newData: () => ({data: { /* ... */ }})
  }
];
const link = new MockLink(fakeData);

Version

  System:
    OS: Linux 4.4 Debian GNU/Linux 9 (stretch) 9 (stretch)
  Binaries:
    Node: 8.15.0 - /usr/bin/node
    Yarn: 1.16.0 - ~/bin/yarn
    npm: 6.4.1 - /usr/bin/npm
  npmPackages:
    apollo-boost: ^0.4.4 => 0.4.4
@pawelkleczek10c
Copy link

I have the same issue

@hwillson
Copy link
Member

hwillson commented Oct 1, 2019

Fixed in #3539 (new version coming soon). Thanks @zombiezen @pawelkleczek10c!

@hwillson hwillson closed this as completed Oct 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants