本文整理汇总了TypeScript中test/TestSupport.wait_for_promise函数的典型用法代码示例。如果您正苦于以下问题:TypeScript wait_for_promise函数的具体用法?TypeScript wait_for_promise怎么用?TypeScript wait_for_promise使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wait_for_promise函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('correctly invalidates cache and does not fetch', () => {
const resource = new Resource(schema.users);
const store = schema.__node.definition.storeMap.getOrCreate('user');
spy(store, 'invalidate');
return wait_for_promise(() => resource.status === IStatus.complete)
.then(() => {
expect(mock_request_count()).to.equal(1);
resource.invalidate({ foo: 123, noFetchGet: true });
expect(store.invalidate.callCount).to.equal(1);
expect(store.invalidate.getCall(0).args[1]).to.deep.equal({
foo: 123,
noFetchGet: true,
invoker: resource
});
expect(resource.status).to.equal(IStatus.stale);
expect(resource.timestamp).to.equal(ITimestamp.stale);
expect(mock_request_count()).to.equal(1);
})
.then(delay_for())
.then(() => {
// no request occurs after invalidating
expect(mock_request_count()).to.equal(1);
expect(resource.status).to.equal(IStatus.stale);
expect(resource.timestamp).to.equal(ITimestamp.stale);
});
});
示例2: expect
.then(() => {
// prove Resource made no request
expect(resource.data).to.equal(null);
expect(resource.status).to.equal(IStatus.stale);
expect(resource.timestamp).to.equal(ITimestamp.stale);
expect(mock_request_count()).to.equal(0);
expect(onLoad.callCount).to.equal(0);
expect(onChange.callCount).to.equal(0);
// re-enable fetch get
resource._options.noFetchGet = false;
const fragment = resource._fetchFragment();
expect(fragment).is.instanceof(FragmentResult);
expect(fragment.data).to.equal(null);
expect(fragment.status).to.equal(IStatus.stale);
expect(fragment.timestamp).to.equal(ITimestamp.loading);
expect(resource.data).to.equal(null);
expect(resource.status).to.equal(IStatus.stale);
expect(resource.timestamp).to.equal(ITimestamp.loading);
expect(onLoad.callCount).to.equal(0);
expect(onChange.callCount).to.equal(0);
return wait_for_promise(() => resource.status === IStatus.complete)
.then(() => {
expect(onLoad.callCount).to.equal(1);
expect(onChange.callCount).to.equal(1);
expect(mock_request_count()).to.equal(1);
expect(resource.data).to.deep.equal(dataCollectionUsers);
expect(resource.status).to.equal(IStatus.complete);
expect(resource.timestamp).to.not.equal(ITimestamp.loading);
});
});