UNPKG

playwright-fluent

Version:
54 lines (53 loc) 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path_1 = tslib_1.__importDefault(require("path")); const SUT = tslib_1.__importStar(require("../index")); const index_1 = require("../index"); const request_mock_1 = require("./request.mock"); describe('har-reader', () => { test('should find response for an http GET', async () => { // Given const harFile = path_1.default.join(__dirname, 'har-get.har'); const harData = (0, index_1.getHarDataFrom)(harFile); const request = { ...request_mock_1.mockRequest, url: () => 'http://localhost:8080/foobar?foo=bar', method: () => 'GET', }; // When const result = SUT.getHarResponseFor(request, harData); // Then expect(result).toBeDefined(); }); test('should find response for an http POST', async () => { // Given const harFile = path_1.default.join(__dirname, 'har-post.har'); const harData = (0, index_1.getHarDataFrom)(harFile); const request = { ...request_mock_1.mockRequest, url: () => 'http://localhost:8080/foobar?foo=bar', method: () => 'POST', postData: () => '{"foo":"bar"}', }; // When const result = SUT.getHarResponseFor(request, harData); // Then expect(result).toBeDefined(); }); test('should not find response for an http POST with unfound postdata', async () => { // Given const harFile = path_1.default.join(__dirname, 'har-post.har'); const harData = (0, index_1.getHarDataFrom)(harFile); const request = { ...request_mock_1.mockRequest, url: () => 'http://localhost:8080/foobar?foo=bar', method: () => 'POST', postData: () => '{"foo":"baz"}', }; // When const result = SUT.getHarResponseFor(request, harData); // Then expect(result).toBeUndefined(); }); });