本文整理匯總了TypeScript中xhr-mock.post函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript post函數的具體用法?TypeScript post怎麽用?TypeScript post使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了post函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should return a JSON object', done => {
mock.post('/some-url', {
body: JSON.stringify({data: 'mockdata'})
});
ajax({
url: '/some-url',
body: {some: 'something'},
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
responseType: 'json'
}).subscribe({
next: response => {
try {
expect(response.response).to.be.deep.equal({
data: 'mockdata'
});
} catch (error) {
done(error);
}
},
error: error => done(error),
complete: () => done()
});
});
示例2: it
it('should receive a request containing a blob', done => {
mock.post('/files', (req, res) => {
expect(req.header('content-type')).to.equal('image/png');
expect(req.body()).to.equal(data);
return res;
});
const data = new Blob(['<h1>Hello World!</h1>'], {type: 'image/png'});
const req = new XMLHttpRequest();
req.open('POST', '/files');
req.onload = () => {
done();
};
req.send(data);
});