How to use the fetch-mock.postOnce 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 guardian / facia-tool / client-v2 / src / actions / __tests__ / Fronts.spec.ts View on Github external
it('should fetch all of the front collections, mark  first collections as open, and fetch articles and their analytics data for  first collections', async () => {
      fetchMock.postOnce('/collections', scJohnsonPartnerZoneCollection);
      fetchMock.post('begin:/stories-visible', {
        desktop: 2,
        mobile: 4
      });
      fetchMock.once(
        'begin:/api/preview/search?ids=internal-code/page/5607373,internal-code/page/5607569',
        articlesForScJohnsonPartnerZone
      );

      // @todo -- this isn't checking the correct thing -- we'd expect article paths in this string.
      // See below -- the articles don't end up in the state as expected.
      fetchMock.get(
        '/ophan/histogram?referring-path=/sc-johnson-partner-zone&hours=1&interval=10',
        []
      );
github auth0 / react-native-auth0 / src / networking / __tests__ / index.spec.js View on Github external
it('should build proper request with no body', async () => {
        fetchMock.postOnce('https://samples.auth0.com/method', response);
        expect.assertions(1);
        await client.post('/method');
        expect(fetchMock.lastCall()).toMatchSnapshot();
      });
github zengfenfei / ringcentral-ts / test / index.ts View on Github external
it('send sms, post plain object', () => {
		fetchMock.postOnce('end:/account/~/extension/~/sms', {});
		let reqBody = {
			from: { phoneNumber: '+17322764403' },
			text: 'test sms text content.',
			to: [{ phoneNumber: '+16507411615' }],
		};
		return rc.account().extension().sms().post(reqBody).then(sms => {
			expect(fetchMock.lastOptions().body).to.deep.eq(JSON.stringify(reqBody));
		});
	});
github zengfenfei / ringcentral-ts / test / setup.ts View on Github external
export async function auth() {
	let rc = new RingCentral({ appKey: 'testAppKey', appSecret: 'testAppSecret' });

	let serverToken = {
		access_token: 'MockAccessToken',
		token_type: 'bearer',
		expires_in: 3600,
		refresh_token: 'MockRefreshToken',
		refresh_token_expires_in: 604800,
		scope: 'ReadMessages Faxes ReadPresence EditCallLog VoipCalling ReadClientInfo Glip Interoperability Contacts ReadAccounts EditExtensions RingOut SMS InternalMessages SubscriptionWebhook EditMessages',
		owner_id: 'MockOwnerId',
		endpoint_id: 'MockEndpointId'
	};
	fetchMock.postOnce('*', serverToken);
	await rc.auth({ username: 'testUserName', password: 'testPassword' });
	return rc;
}
github teambition / teambition-sdk / test / apis / scenariofieldconfig.spec.ts View on Github external
const projectId = config._boundToObjectId as ProjectId
    const configIds = [configId]
    const configs = [config]

    fetchMock.getOnce('*', [])

    const configs$ = sdk
      .getScenarioFieldConfigs(projectId, 'event')
      .take(1)
      .subscribeOn(Scheduler.asap)

    yield configs$.do((result) => {
      expect(result).to.be.empty
    })

    fetchMock.postOnce('*', configs)

    yield sdk
      .bulkAddScenarioFieldConfigs(projectId, 'event', configIds)
      .subscribeOn(Scheduler.asap)
      .do(([result]) => {
        assertScenarioFieldConfig(result, configs[0])
      })

    yield configs$.do(([result]) => {
      assertScenarioFieldConfig(result, configs[0])
    })
  })
github google / skia-buildbot / ct / modules / task-queue-sk / task-queue-sk-demo.ts View on Github external
function newTaskQueue(parentSelector: string) {
  fetchMock.config.overwriteRoutes = false;
  fetchMock.postOnce('begin:/_/get_', resultSetTwoItems);
  fetchMock.postOnce('begin:/_/get_', singleResultCanDelete);
  fetchMock.postOnce('begin:/_/get_', singleResultNoDelete);
  fetchMock.post('begin:/_/get_', 200, { repeat: 13 });
  const tq = document.createElement('task-queue-sk');
  ($$(parentSelector) as HTMLElement).appendChild(tq);
}
github google / skia-buildbot / ct / modules / task-queue-sk / task-queue-sk-demo.ts View on Github external
function newTaskQueue(parentSelector: string) {
  fetchMock.config.overwriteRoutes = false;
  fetchMock.postOnce('begin:/_/get_', resultSetTwoItems);
  fetchMock.postOnce('begin:/_/get_', singleResultCanDelete);
  fetchMock.postOnce('begin:/_/get_', singleResultNoDelete);
  fetchMock.post('begin:/_/get_', 200, { repeat: 13 });
  const tq = document.createElement('task-queue-sk');
  ($$(parentSelector) as HTMLElement).appendChild(tq);
}
github google / skia-buildbot / ct / modules / task-queue-sk / task-queue-sk-demo.ts View on Github external
function newTaskQueue(parentSelector: string) {
  fetchMock.config.overwriteRoutes = false;
  fetchMock.postOnce('begin:/_/get_', resultSetTwoItems);
  fetchMock.postOnce('begin:/_/get_', singleResultCanDelete);
  fetchMock.postOnce('begin:/_/get_', singleResultNoDelete);
  fetchMock.post('begin:/_/get_', 200, { repeat: 13 });
  const tq = document.createElement('task-queue-sk');
  ($$(parentSelector) as HTMLElement).appendChild(tq);
}