Check out example codes for "integrationtest typescript". It will help you in understanding the concepts better.

Code Example 1

it(`GIVEN an id = "${id}", WHEN getDetailedVehicle() is executed, THEN the Promise will be resolved with ${expectedVehicleDto}.`, async () => {
            (VehicleRepository.findOne as SinonStub).withArgs(id).resolves(vehicleEntity);
            (ClassTransformer.plainToClass as SinonStub).withArgs(VehicleDto, vehicleEntity).returns(vehicleDto);
            (DamageService.getDamageState as SinonStub).withArgs(vehicleDto.id).resolves(true);
 
            const result = VehicleService.getDetailedVehicle(id);
 
            await expect(result).to.be.eventually.deep.equal(expectedVehicleDto);
});

Code Example 2

describe('Contract test for DamageService: getDamageState', () => {
    const provider: Pact = new Pact({
        consumer: 'vehicle-service',
        provider: 'damage-service',
        port: 8080,
        host: 'localhost',
        dir: resolve(__dirname, '../contract/pacts'),
        log: resolve(__dirname, '../contract/logs/pact.log'),
        spec: 2,
    });
    const BASIC_AUTH_MATCHER: string = '^Basic ';
 
    const damagedVehicleId = '1';
    const notDamagedVehicleId = '2';
    const nonExistingDamagedVehicleId = '17';
 
    const validInteractionForDamagedVehicle = new Interaction()
        .given(`Valid vehicle ID = ${damagedVehicleId}`)
        .uponReceiving('a valid vehicle ID from Vehicle Service')
        .withRequest({
            method: 'GET',
            path: `/damage/vehicle/${damagedVehicleId}`,
            headers: {
                [AUTHORIZATION_HEADER]: Matchers.term({
                    generate: `Basic ${BASIC_AUTH}`,
                    matcher: BASIC_AUTH_MATCHER,
                }),
            },
        })
        .willRespondWith({
            status: OK,
            body: Matchers.somethingLike({ damaged: true }),
        });
  
    before(async () => {
        await provider.setup();
    });
 
    after(async () => {
        await provider.finalize();
    });
 
    afterEach(async () => {
        await provider.removeInteractions();
    });
 
    it(`GIVEN vehicle id="${damagedVehicleId}", WHEN getDamageState() is executed, THEN the Promise will be resolved with true.`, async () => {
        await provider.addInteraction(validInteractionForDamagedVehicle);
 
        const result = DamageService.getDamageState(damagedVehicleId);
 
        await expect(result).to.be.eventually.true;
        await expect(provider.verify()).to.not.be.rejected;
    });

Code Example 3

    it('GIVEN a valid vehicle, WHEN posting to vehicles endpoint, THEN a Response with HTTP STATUS OK and the created vehicle will be sent.', async () => {
        const vehicle = {
            id: '1',
            color: 1,
        };
 
        const result = await chai.request(App)
            .post(VEHICLE_ENDPOINT)
            .send(vehicle);
 
        expect(result).to.have.status(OK);
        expect(result.body).to.be.deep.equal(vehicle);
    });

Code Example 4

it(`GIVEN vehicle id="${healthyVehicle.id}", WHEN getDamageState() is executed THEN the Promise will be resolved with false.`, async () => {
 
            const result = DamageService.getDamageState(healthyVehicle.id);
 
            await expect(result).to.be.eventually.false;
});

Learn ReactJs, React Native from akashmittal.com