本文整理汇总了TypeScript中test/TestSupport.delay_for_resource_request函数的典型用法代码示例。如果您正苦于以下问题:TypeScript delay_for_resource_request函数的具体用法?TypeScript delay_for_resource_request怎么用?TypeScript delay_for_resource_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了delay_for_resource_request函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('correctly invalidates cache and fetches', () => {
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);
mock_get('/users', dataCollectionUsers);
resource.invalidate({ foo: 123 });
expect(store.invalidate.callCount).to.equal(1);
expect(store.invalidate.getCall(0).args[1]).to.deep.equal({
foo: 123,
invoker: resource
});
expect(resource.status).to.equal(IStatus.stale);
expect(resource.timestamp).to.equal(ITimestamp.loading);
expect(mock_request_count()).to.equal(1);
})
.then(delay_for_resource_request(resource))
.then(() => {
expect(mock_request_count()).to.equal(2);
expect(resource.status).to.equal(IStatus.complete);
expect(resource.timestamp).to.not.equal(ITimestamp.stale);
});
});
示例2: it
it('properly updates collections when mutated', () => {
mock_get('/users', dataCollectionUsers1);
const resourceUsers = new Resource(schema.users);
const mutableUser = new MutableResource(schema.users.user.withParams({
userId: 1
}));
expect(resourceUsers).to.deep.match({
data: null,
status: IStatus.stale,
timestamp: ITimestamp.loading
});
return delay_for_resource_request(resourceUsers)()
.then(() => {
expect(resourceUsers).to.deep.match({
data: dataCollectionUsers1,
status: IStatus.complete,
timestamp: (val: number) => val > ITimestamp.loading
});
mock_put('/users/1', { id: 1, name: 'bob foo' });
const promiseUpdate = mutableUser.update({ name: 'bob foo' });
// The `touch` event from our `update` does not affect the collection
expect(resourceUsers).to.deep.match({
data: dataCollectionUsers1,
status: IStatus.complete,
timestamp: (val: number) => val > ITimestamp.loading
});
return promiseUpdate;
})
.then(() => {
// The `update` event from our `update` action should update the collection
expect(resourceUsers).to.deep.match({
data: [
{ id: 1, name: 'bob foo' },
dataElement2
],
status: IStatus.complete,
timestamp: (val: number) => val > ITimestamp.loading
});
});
});