fix(requestInterceptor): use async/await to support return new Promise (#6279)

ref: #4778
This commit is contained in:
Tim Lai
2020-07-31 10:07:52 -07:00
committed by GitHub
parent 752488edf7
commit abcc3837e9
2 changed files with 7 additions and 6 deletions

View File

@@ -429,8 +429,8 @@ export const executeRequest = (req) =>
specActions.setRequest(req.pathName, req.method, parsedRequest)
let requestInterceptorWrapper = function(r) {
let mutatedRequest = requestInterceptor.apply(this, [r])
let requestInterceptorWrapper = async (r) => {
let mutatedRequest = await requestInterceptor.apply(this, [r])
let parsedMutatedRequest = Object.assign({}, mutatedRequest)
specActions.setMutatedRequest(req.pathName, req.method, parsedMutatedRequest)
return mutatedRequest

View File

@@ -93,7 +93,7 @@ describe("spec plugin - actions", function(){
})
})
it("should pass requestInterceptor/responseInterceptor to fn.execute", function(){
it("should pass requestInterceptor/responseInterceptor to fn.execute", async () => {
// Given
let configs = {
requestInterceptor: createSpy(),
@@ -107,7 +107,8 @@ describe("spec plugin - actions", function(){
specActions: {
executeRequest: createSpy(),
setMutatedRequest: createSpy(),
setRequest: createSpy()
setRequest: createSpy(),
setResponse: createSpy()
},
specSelectors: {
spec: () => fromJS({}),
@@ -124,7 +125,7 @@ describe("spec plugin - actions", function(){
method: "GET",
operation: fromJS({operationId: "getOne"})
})
let res = executeFn(system)
await executeFn(system)
// Then
expect(system.fn.execute.calls.length).toEqual(1)
@@ -137,7 +138,7 @@ describe("spec plugin - actions", function(){
let wrappedRequestInterceptor = system.fn.execute.calls[0].arguments[0].requestInterceptor
wrappedRequestInterceptor(system.fn.execute.calls[0].arguments[0])
await wrappedRequestInterceptor(system.fn.execute.calls[0].arguments[0])
expect(configs.requestInterceptor.calls.length).toEqual(1)
expect(system.specActions.setMutatedRequest.calls.length).toEqual(1)
expect(system.specActions.setRequest.calls.length).toEqual(1)