当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript fetch-mock.once函数代码示例

本文整理汇总了TypeScript中fetch-mock.once函数的典型用法代码示例。如果您正苦于以下问题:TypeScript once函数的具体用法?TypeScript once怎么用?TypeScript once使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了once函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

  it('decrements loading count when requests fail', async () => {
    fetchMock.once('*', {
      body: { settings: {} },
    });
    fetchMock.once('*', {
      status: 400,
      body: 'invalid',
    });

    const { uiSettingsApi } = setup();
    const done$ = new Rx.Subject();
    const promise = uiSettingsApi
      .getLoadingCount$()
      .pipe(
        takeUntil(done$),
        toArray()
      )
      .toPromise();

    await uiSettingsApi.batchSet('foo', 'bar');
    await expect(uiSettingsApi.batchSet('foo', 'bar')).rejects.toThrowError();

    done$.next();
    await expect(promise).resolves.toEqual([0, 1, 0, 1, 0]);
  });
开发者ID:austec-automation,项目名称:kibana,代码行数:25,代码来源:ui_settings_api.test.ts

示例2: test

test('Schema migration displaying data loss', async t => {
  // configure HTTP mocks
  fetchMock.once(systemAPIEndpoint, JSON.parse(mockedPullProjectResponse1))
  fetchMock.once(systemAPIEndpoint, JSON.parse(mockedPushSchema1ResponseError))

  // dummy migration data
  const projectFile = 'project.graphcool'
  const env = testEnvironment({})
  env.resolver.write(projectFile, mockModifiedProjectFile1)
  env.resolver.write(graphcoolConfigFilePath, '{"token": ""}')
  const props = { force: true }

  env.out.prefix((t as any)._test.title, `$ graphcool push`)

  await t.notThrows(
    push(props, env)
  )

  t.is(env.resolver.read(projectFile), mockModifiedProjectFile1)
})
开发者ID:sadeeqaji,项目名称:graphcool-cli,代码行数:20,代码来源:push.test.ts

示例3:

    headers: {
        test: "header"
    }
});
fetchMock.mock("http//test.com", 200, {
    query: {
        searchValue: "apples"
    }
});
fetchMock.mock("http://test.com", 200, {
    repeat: 2
});
fetchMock.mock(/test\.com/, 200);
fetchMock.mock(() => true, 200);
fetchMock.mock((url, opts) => true, 200);
fetchMock.once("http://test.com", 200);

fetchMock.mock(/test/, "test").mock(/test/, { a: "b" });
fetchMock.mock(/test/, {
    status: 200,
    headers: {
        test: "test"
    },
    body: {
        a: "b"
    }
});

fetchMock.restore().reset();

(fetchMock.calls().matched[0][1] as RequestInit).body;
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:31,代码来源:fetch-mock-tests.ts


注:本文中的fetch-mock.once函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。