本文整理匯總了TypeScript中xhr-mock.use函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript use函數的具體用法?TypeScript use怎麽用?TypeScript use使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了use函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should PUT', async () => {
mock.use((req, res) => {
expect(req.method()).to.eq('PUT');
expect(String(req.url())).to.eq('/');
expect(req.body()).to.eq(JSON.stringify({foo: 'bar'}));
return res
.status(200)
.reason('OK')
.header('Content-Length', '12')
.body('Hello World!');
});
const res = await $.ajax({
method: 'put',
url: '/',
data: JSON.stringify({foo: 'bar'})
})
.then((data, status, xhr) => {
expect(xhr.status).to.eq(200);
expect(xhr.statusText).to.eq('OK');
expect(xhr.getAllResponseHeaders()).to.contain(
'content-length: 12\r\n'
);
expect(data).to.eq('Hello World!');
})
.catch((xhr, status, error) => expect.fail(error));
});
示例2: it
it('should DELETE', async () => {
mock.use((req, res) => {
expect(req.method()).to.eq('DELETE');
expect(String(req.url())).to.eq('/');
expect(req.body()).to.eq(null);
return res.status(204).reason('No Content');
});
const res = await superagent.delete('/');
expect(res.status).to.eq(204);
// expect(res.statusText).to.eq('No Content');
expect(res.header).not.to.have.property('content-length', '12');
expect(res.text).to.eq('');
});
示例3: it
it('should DELETE', async () => {
mock.use((req, res) => {
expect(req.method()).to.eq('DELETE');
expect(String(req.url())).to.eq('/');
expect(req.body()).to.eq(null);
return res.status(204).reason('No Content');
});
const res = await axios.delete('/');
expect(res.status).to.eq(204);
expect(res.statusText).to.eq('No Content');
expect(res.headers).to.deep.eq({});
expect(res.data).to.eq('');
});