How to use the jest-fetch-mock.mockReject function in jest-fetch-mock

To help you get started, we’ve selected a few jest-fetch-mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BlueBrain / nexus-js / src / View / ElasticSearchView / __tests__ / ElasticSearchView.spec.ts View on Github external
it('should throw an error if httpPost crashes', async () => {
      const view = new ElasticSearchView(
        orgLabel,
        projectLabel,
        mockElasticSearchViewResponse,
      );
      const message = 'some error message';
      mockReject(Error(message));
      await expect(view.aggregation(mockAggregationQuery)).rejects.toThrow(
        Error,
      );
    });
github unosquare / tubular-react / test / RemoteDataSource.spec.tsx View on Github external
test('Should have error with invalid url', (done) => {
    fetch.mockReject(new Error('Bad Request'));

    const component = shallow();
    (component.instance() as any).retrieveData().then(() => {
      expect(component.state('data')).toEqual([]);
      expect(component.state('error')).toBeDefined();
      done();
    });
  });
github BlueBrain / nexus-js / src / View / ElasticSearchView / __tests__ / ElasticSearchView.spec.ts View on Github external
it('should throw an error if httpPost crashes', async () => {
      const view = new ElasticSearchView(
        orgLabel,
        projectLabel,
        mockElasticSearchViewResponse,
      );
      const myQuery = {};
      mockReject(new Error('very bad'));

      await expect(view.rawQuery(myQuery)).rejects.toThrow(Error);
    });