How to use the fetch-mock.getOnce 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 teambition / teambition-sdk / test / apis / scenariofieldconfig.spec.ts View on Github external
const customfieldlinksUrl = `/projects/${projectId}/customfieldlinks?boundType=application&withRootCommongroup=true&_=666`
    fetchMock.getOnce(customfieldlinksUrl, [customFieldLink])

    // 缓存 CustomFieldLink 数据
    yield sdk
      .getCustomFieldLinks(projectId, 'application')
      .values()
      .subscribeOn(Scheduler.asap)
      .do(() => {
        expect(fetchMock.called(customfieldlinksUrl)).to.be.true
      })

    // 请求 CustomField 数据,无权限
    const customFieldUrl = `/customfields/${customFieldId}?_=666`
    fetchMock.getOnce(customFieldUrl, 403)

    yield configs$.do(([result]) => {
      assertScenarioFieldConfig(result, {
        ...config,
        ...nextConfig,
        scenariofields: [{ ...nextScenarioField, customfield: customField }]
      })

      expect(fetchMock.called(customFieldUrl)).to.be.true
    })
  })
github teambition / teambition-sdk / test / apis / scenariofieldconfig.spec.ts View on Github external
const customScenarioField = {
      fieldType: 'customfield',
      _customfieldId: customFieldId
    } as CustomScenarioFieldSchema

    const configId = 'mock-sfc-id' as ScenarioFieldConfigId
    const orgId = 'mock-org-id' as OrganizationId
    const objectType = 'task'
    const config = {
      _id: configId,
      _boundToObjectId: orgId,
      objectType,
      scenariofields: [customScenarioField] as ScenarioFieldSchema[]
    } as ScenarioFieldConfigSchema

    fetchMock.getOnce('*', { result: [config] })

    const customFieldUrl = `/customfields/${customFieldId}?_=666`
    fetchMock.getOnce(customFieldUrl, customField)

    yield sdk
      .getOrgScenarioFieldConfigs(orgId, objectType)
      .take(1)
      .subscribeOn(Scheduler.asap)
      .do(([result]) => {
        // 填补了 CustomField 数据
        const resultScenarioField = result
          .scenariofields[0] as CustomScenarioFieldSchema
        expectToDeepEqualForFieldsOfTheExpected(
          resultScenarioField.customfield,
          customField
        )
github zengfenfei / ringcentral-ts / test / index.ts View on Github external
it('gets current profile image', function () {
		fetchMock.getOnce('end:/account/~/extension/~/profile-image', { fake: 'data' });
		return rc.account().extension().profileImage().get();
	});
github zengfenfei / ringcentral-ts / test / index.ts View on Github external
it('Get message content as binary', async () => {
		let dateFrom = new Date().toISOString();
		fetchMock.getOnce('end:/account/~/extension/~/message-store?dateFrom=' + encodeURIComponent(dateFrom), { fake: 'data' });
		await rc.account().extension().messageStore().list({ dateFrom });

		fetchMock.getOnce('end:/account/~/extension/~/message-store/the-message-id/content/content-id', { fake: 'data' });
		await rc.account().extension().messageStore('the-message-id').content('content-id').get();
	});
github teambition / teambition-sdk / test / apis / search.spec.ts View on Github external
it(`${fn.name} should return empty result set as it is`, function* () {
        const expectedResultSet: any[] = []
        fetchMock.getOnce(`/${namespace}/${sampleId}/members/search?q=nonExistence&_=666`, expectedResultSet)

        yield fn.call(sdkFetch, sampleId as any, 'nonExistence')
          .subscribeOn(Scheduler.asap)
          .do((x: any) => {
            expect(x).to.deep.equal(expectedResultSet)
          })
      })
    })
github auth0 / react-native-auth0 / src / auth / __tests__ / index.spec.js View on Github external
it('should return successful non-oidc response', async () => {
      fetchMock.getOnce('https://samples.auth0.com/userinfo', {
        sub: 'auth0|1029837475'
      });
      expect.assertions(1);
      await expect(auth.userInfo(parameters)).resolves.toMatchSnapshot();
    });
github samrocksc / howard / test / index.js View on Github external
beforeEach(function() {
    fetchMock.getOnce(config.url + '/get', pass)
    fetchMock.postOnce(config.url + '/post', pass)
    fetchMock.postOnce(config.url + '/checkAuth', { status: 301 });
    fetchMock.getOnce(config.url + '/fail', { status: 404 })
    fetchMock.getOnce(config.url + '/blob', img);
    fetchMock.getOnce(config.url + '/qs?id=1', pass);
    fetchMock.getOnce(config.url + '/arrayBuffer', mockArrayBuffer);
  });
github teambition / teambition-sdk / test / apis / scenariofieldconfig.spec.ts View on Github external
} as CustomScenarioFieldSchema
    const nextConfig: Partial = {
      _id: configId,
      scenariofields: [nextScenarioField]
    }

    fetchMock.putOnce('*', nextConfig)

    yield sdk
      .updateScenarioFieldConfigFields(configId, [nextScenarioField])
      .subscribeOn(Scheduler.asap)
      .do((result) => {
        expect(result).to.deep.equal(nextConfig)
      })

    fetchMock.getOnce('*', customField)

    yield configs$.do(([result]) => {
      assertScenarioFieldConfig(result, {
        ...config,
        scenariofields: [{ ...nextScenarioField, customfield: customField }]
      })
    })
  })
github google / skia-buildbot / status / modules / rotations-sk / rotations-sk-demo.ts View on Github external
import './index';
import '../tree-status-sk';
import fetchMock from 'fetch-mock';
import { $$ } from 'common-sk/modules/dom';
import {
  treeStatusResp,
  generalRoleResp,
  gpuRoleResp,
  androidRoleResp,
  infraRoleResp,
} from '../tree-status-sk/test_data';
import { TreeStatus, TreeStatusSk } from '../tree-status-sk/tree-status-sk';
import { RotationsSk } from './rotations-sk';

fetchMock.getOnce('https://tree-status.skia.org/current', treeStatusResp);
fetchMock.getOnce('https://chrome-ops-rotation-proxy.appspot.com/current/grotation:skia-gardener', generalRoleResp);
fetchMock.getOnce('https://chrome-ops-rotation-proxy.appspot.com/current/grotation:skia-gpu-gardener', gpuRoleResp);
fetchMock.getOnce('https://chrome-ops-rotation-proxy.appspot.com/current/grotation:skia-android-gardener', androidRoleResp);
fetchMock.getOnce('https://chrome-ops-rotation-proxy.appspot.com/current/grotation:skia-infra-gardener', infraRoleResp);
Date.now = () => 1600883976659;

const ts = document.createElement('tree-status-sk') as TreeStatusSk;
const r = document.createElement('rotations-sk') as RotationsSk;
ts.addEventListener('tree-status-update', (e) => {
  r.rotations = (e as CustomEvent).detail.rotations;
});
($$('#container') as HTMLElement).appendChild(ts);
($$('#container') as HTMLElement).appendChild(r);
github google / skia-buildbot / status / modules / rotations-sk / rotations-sk-demo.ts View on Github external
import fetchMock from 'fetch-mock';
import { $$ } from 'common-sk/modules/dom';
import {
  treeStatusResp,
  generalRoleResp,
  gpuRoleResp,
  androidRoleResp,
  infraRoleResp,
} from '../tree-status-sk/test_data';
import { TreeStatus, TreeStatusSk } from '../tree-status-sk/tree-status-sk';
import { RotationsSk } from './rotations-sk';

fetchMock.getOnce('https://tree-status.skia.org/current', treeStatusResp);
fetchMock.getOnce('https://chrome-ops-rotation-proxy.appspot.com/current/grotation:skia-gardener', generalRoleResp);
fetchMock.getOnce('https://chrome-ops-rotation-proxy.appspot.com/current/grotation:skia-gpu-gardener', gpuRoleResp);
fetchMock.getOnce('https://chrome-ops-rotation-proxy.appspot.com/current/grotation:skia-android-gardener', androidRoleResp);
fetchMock.getOnce('https://chrome-ops-rotation-proxy.appspot.com/current/grotation:skia-infra-gardener', infraRoleResp);
Date.now = () => 1600883976659;

const ts = document.createElement('tree-status-sk') as TreeStatusSk;
const r = document.createElement('rotations-sk') as RotationsSk;
ts.addEventListener('tree-status-update', (e) => {
  r.rotations = (e as CustomEvent).detail.rotations;
});
($$('#container') as HTMLElement).appendChild(ts);
($$('#container') as HTMLElement).appendChild(r);