Skip to content

Using the same request object for multiple test cases #106

Discussion options

You must be logged in to vote

In general objects are accessed by reference. If you update a value inside the object, it will be reflected at other places. The easiest solution is to have independent objects per test case.

Using clone

You can create a clone the request object for each test case and modify accordingly. Fortunately pactum comes with an inbuilt function to clone objects. Or use JSON.parse(JSON.stringify(object))

it('Verify creation of HCF with exisiting salesforce id', async () => {
    const body = pactum.clone(request.createFacilityWithRequiredFields);
    body.salesforceID =  configData.salesforceid
    await pactum.spec()
        .post(endpoints.baseUrl + endpoints.createHCF)
        .withBody(body)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@vinayak-kaladhar
Comment options

Answer selected by vinayak-kaladhar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants