Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | // import {InterfaceProxy} from '../../src/index.js';
import iProxy from './iProxy';
describe("instance interface responses", () => {
// JSON success then
it("with default json pattern should resolve {success:true,...} as success and extract data", (done) => {
iProxy.jsonSuccess().then(data => {
expect(data).toEqual({name: 'wdzxc'});
done();
});
});
// JSON error catch
it("with default json pattern should resolve {success:false,...} as error and extract error msg", (done) => {
iProxy.jsonFail().catch(msg => {
expect(msg).toBe('server error');
done();
});
});
// 失败回调
it("should call error callback when response status is error", (done) => {
iProxy.jsonFail(() => {
// placeholder for success callback
}, msg => {
expect(msg).toBe('server error');
done();
});
});
// 响应预处理 配置项 dataPath
it("should auto extract response data according to dataPath config", (done) => {
iProxy.userName({name: 'wdzxc'}).then(data => {
expect(data).toEqual('wdzxc');
done();
});
});
// JSON finally
it("always call finally after catch & then ", (done) => {
iProxy.jsonFail().catch(msg => {
}).finally(() => {
done();
});
});
}); |