How to use jest-mock-axios - 10 common examples

To help you get started, we’ve selected a few jest-mock-axios 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 indico / indico / indico / modules / events / editing / client / js / __tests__ / FileManager.spec.jsx View on Github external
afterEach(() => {
  // cleaning up the mess left behind the previous test
  mockAxios.reset();
  React.resetMocks();
});
github klarstil / lifx-http-api / __tests__ / lifx / lifx-factory.spec.ts View on Github external
afterEach(() => {
    // cleaning up the mess left behind the previous test
        mockAxios.reset();
    });
github indico / indico / indico / modules / events / editing / client / js / __tests__ / FileManager.spec.jsx View on Github external
// replace the newly uploaded file
    const uuid = await uploadFile(dropzone, onChange, 'test2.pdf', 'pdf', 'newtest1.pdf');
    wrapper.update();
    const fileEntry = getFileEntryForFileType(wrapper, 2);
    checkFileEntry(fileEntry, 'test2.pdf', 'trash');

    // perform an undo - this needs to go back to an empty file list
    await act(async () => {
      fileEntry.find('FileAction').simulate('click');
      mockAxios.mockResponse(
        undefined,
        mockAxios.mustGetReqByUrl(`flask://files.delete_file/uuid=${uuid}`)
      );
    });
    expect(mockAxios.delete).toHaveBeenCalledWith(`flask://files.delete_file/uuid=${uuid}`);
    expect(onChange).toHaveBeenCalledWith({});
  });
github indico / indico / indico / modules / events / editing / client / js / __tests__ / FileManager.spec.jsx View on Github external
onChange={onChange}
      />
    );
    const dropzone = getDropzoneForFileType(wrapper, 2);

    const file1 = {type: 'pdf', name: 'test.pdf'};

    // simulate actual "drop" event
    await act(async () => {
      dropzone.simulate('drop', createDtWithFiles([file1]));
    });

    const mockDispatch = React.mockDispatches[0];

    // the upload endpoint is properly called
    expect(mockAxios.post).toHaveBeenCalledWith(
      'http://upload/endpoint',
      expect.toContainFile(file1),
      expect.anything()
    );

    // the internal state is updated
    expect(mockDispatch).toHaveBeenCalledWith(
      expect.objectContaining({type: actions.START_UPLOADS})
    );

    expect(onChange).not.toHaveBeenCalled();

    await act(async () => {
      mockAxios.mockResponse(
        {
          data: {
github klarstil / lifx-http-api / __tests__ / lifx / lifx-factory.spec.ts View on Github external
it('should set a state delta', (done) => {
        const token = process.env.TOKEN as string;
        const factory = new LifxFactory(token);
        const selector = (new SelectorCriteria())
            .setAll();

        const state = new StateCriteria(selector);
        state.setColor((new ColorCriteria()).setName('green'));

        factory.setStateDelta(state).then((result: LifxEffectResult) => {
            expect(result.results.length).toBe(1);
            done();
        });

        mockAxios.mockResponse({ data: effectFixtures } as AxiosResponse);
    });
github indico / indico / indico / modules / events / editing / client / js / __tests__ / FileManager.spec.jsx View on Github external
await act(async () => {
    mockAxios.mockResponse(
      {
        data: {
          uuid,
          filename: name,
          claimed: false,
          downloadURL: 'goes://nowhere',
        },
      },
      mockAxios.mustGetReqByUrl('goes://nowhere')
    );
  });
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-account / src / __tests__ / wallet.spec.ts View on Github external
const [wallet] = createWallet(1);
    const pubKey = (wallet.defaultAccount &&
      wallet.defaultAccount.publicKey) as string;

    const tx = new Transaction({
      version: 1,
      nonce: 1,
      to: '0x1234567890123456789012345678901234567890',
      amount: new BN(0),
      gasPrice: 1000,
      gasLimit: 1000,
      pubKey,
    });

    const signed = wallet.sign(tx);
    mockAxios.mockResponse({
      data: {
        result: {nonce: 1},
      },
    });

    return signed.then(tx => {
      const bytes = tx.bytes;
      const signature = schnorr.toSignature(tx.return().signature as string);
      const lgtm = schnorr.verify(bytes, signature, Buffer.from(pubKey, 'hex'));

      expect(lgtm).toBeTruthy();
    });
  });
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-account / src / __tests__ / transaction.spec.ts View on Github external
return tx.then(tx => {
      tx.confirmReceipt('some_hash').map(txObj => {
        expect(txObj.id).toEqual('some_hash');
        expect(txObj.receipt).toEqual({succcess: true, cumulative_gas: 1000});
        expect(tx.isPending()).toBeFalsy();
        expect(tx.isConfirmed()).toBeTruthy();
        return txObj;
      });

      mockAxios.mockResponse({
        data: {
          result: {
            ID: 'some_hash',
            receipt: {
              success: true,
              cumulative_gas: 1000,
            },
          },
        },
      });
    });
  });
github indico / indico / indico / modules / events / editing / client / js / __tests__ / FileManager.spec.jsx View on Github external
await act(async () => {
      mockAxios.mockResponse(undefined, mockAxios.mustGetReqByUrl(deleteUrl));
    });
  } else {
github indico / indico / indico / modules / events / editing / client / js / __tests__ / FileManager.spec.jsx View on Github external
await act(async () => {
      fileEntry.find('FileAction').simulate('click');
      mockAxios.mockResponse(
        undefined,
        mockAxios.mustGetReqByUrl(`flask://files.delete_file/uuid=${uuid}`)
      );
    });
    expect(mockAxios.delete).toHaveBeenCalledWith(`flask://files.delete_file/uuid=${uuid}`);