using pactum in a class method returns a promise #185
Answered
by
ASaiAnudeep
AndyB-Test
asked this question in
Q&A
-
Using await spec() inside a class method returns const { spec } = require('pactum');
class ApiHandler {
getUuid(input){
async function getInfo(assetName){
const infoGet = await spec()
.get(URL)
.expectStatus(200)
.expectJson('status','success')
.returns('.data')
const result = infoGet()
return(result.uuid)
};
return getInfo(input)
};
}; called using: const ApiHandler = require('apiHandler');
this.apiHandler = new ApiHandler()
console.log(this.apiHandler.getUuid('name')) Anything obviously wrong? when run in the same file from an async function it's working fine |
Beta Was this translation helpful? Give feedback.
Answered by
ASaiAnudeep
Jul 19, 2022
Replies: 1 comment 1 reply
-
The method console.log(await this.apiHandler.getUuid('name')) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ASaiAnudeep
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The method
getUuid
returns the result ofgetInfo
function which is a promise. So we need to put anawait
statement before the function call.