How to use the fetch-mock.lastOptions function in fetch-mock

To help you get started, we’ve selected a few 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 Workfront / workfront-api / test / integration / count.spec.ts View on Github external
return this.api.count('foo').then(function() {
            const opts = fetchMock.lastOptions('count')
            should(opts.method).equal('GET')
            should(opts.body).be.null()
        })
    })
github ynab / ynab-sdk-js / test / mockTests.ts View on Github external
it("Should getBudgets and validate the request is sent correctly", async () => {
    let budgetSummary = budgetSummaryFactory.build();
    fetchMock.mock("*", budgetSummary);
    let ynab: ynabApi = new ynabApi(API_KEY, BASE_URL);

    const getBudgetsResponse = await ynab.budgets.getBudgets(0);

    expect(fetchMock.calls().matched.length, "fetchMock calls").to.equal(1);
    expect(fetchMock.lastUrl()).to.equal(`${BASE_URL}/budgets`);
    expect(fetchMock.lastOptions().method).to.equal("GET");
    expect(fetchMock.lastOptions().headers).to.deep.equal({
      Authorization: "Bearer API_KEY"
    });
  });
});
github Workfront / workfront-api / test / integration / logout.spec.ts View on Github external
return this.api.logout('foo', 'bar').then(() => {
                    opts = fetchMock.lastOptions('logout')
                    should(opts.headers.has('sessionID')).be.ok()
                    this.api.login('foo', 'bar')
                    opts = fetchMock.lastOptions('login')
                    should(opts.headers.has('sessionID')).not.be.ok()
                })
            })
github ynab / ynab-sdk-js / test / mockTests.ts View on Github external
it("Should getBudgets and validate the request is sent correctly", async () => {
    let budgetSummary = budgetSummaryFactory.build();
    fetchMock.mock("*", budgetSummary);
    let ynab: ynabApi = new ynabApi(API_KEY, BASE_URL);

    const getBudgetsResponse = await ynab.budgets.getBudgets(0);

    expect(fetchMock.calls().matched.length, "fetchMock calls").to.equal(1);
    expect(fetchMock.lastUrl()).to.equal(`${BASE_URL}/budgets`);
    expect(fetchMock.lastOptions().method).to.equal("GET");
    expect(fetchMock.lastOptions().headers).to.deep.equal({
      Authorization: "Bearer API_KEY"
    });
  });
});
github apollographql / apollo-link / packages / apollo-link-batch-http / src / __tests__ / batchHttpLink.ts View on Github external
const complete = () => {
      try {
        const calls = fetchMock.calls('begin:batch');
        expect(calls.length).toBe(1);
        expect(nextCalls).toBe(2);

        const options = fetchMock.lastOptions('begin:batch');
        expect(options.credentials).toEqual('two');

        const { headers } = options;
        expect(headers['apollographql-client-name']).toBeDefined();
        expect(headers['apollographql-client-name']).toEqual(
          clientAwareness.name,
        );
        expect(headers['apollographql-client-version']).toBeDefined();
        expect(headers['apollographql-client-version']).toEqual(
          clientAwareness.version,
        );

        completions++;

        if (completions === 2) {
          done();
github huridocs / uwazi / app / react / Entities / specs / EntitiesAPI.spec.js View on Github external
it('should post the ids and metadata to /entities/multipleupdate', async () => {
      const values = { metadata: { text: 'document text' } };
      const ids = ['1', '2'];
      const request = new RequestParams({ values, ids });
      const response = await entitiesAPI.multipleUpdate(request);

      expect(JSON.parse(backend.lastOptions(`${APIURL}entities/multipleupdate`).body)).toEqual({ ids, values });
      expect(response).toEqual({ backednResponse: 'test multiple' });
    });
  });
github jpodwys / preact-journal / client / js / xhr / index.spec.js View on Github external
xhr('get-200').then(() => {
      const options = fetchMock.lastOptions();
      expect(options.credentials).to.equal('same-origin');
      expect(Object.keys(options.headers).length).to.equal(2);
      expect(options.headers['Content-Type']).to.equal('application/json');
      expect(options.headers['Accept']).to.equal('application/json');
      done();
    }).catch(done);
  });
github huridocs / uwazi / app / react / Thesauris / actions / specs / thesauriActions.spec.js View on Github external
const expectedActions = [
        { type: types.THESAURI_SAVED },
        { type: notificationsTypes.NOTIFY, notification: { message: 'Thesaurus saved', type: 'success', id: 'unique_id' } },
        { type: 'rrf/change', model: 'thesauri.data', value: { testBackendResult: 'ok' }, silent: false, multi: false, external: true }
      ];
      const store = mockStore({});

      const data = { name: 'Secret list of things', values: [] };
      store.dispatch(actions.saveThesauri(data))
      .then(() => {
        expect(store.getActions()).toEqual(expectedActions);
      })
      .then(done)
      .catch(done.fail);

      expect(JSON.parse(backend.lastOptions(`${APIURL}thesauris`).body)).toEqual(data);
    });
  });