Skip to content

Commit

Permalink
fix: added unit tests
Browse files Browse the repository at this point in the history
Added some more unit tests to increase code coverage
  • Loading branch information
KayleighYum committed Dec 12, 2023
1 parent e91f18d commit 5554bc8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions packages/lib/har/harUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
toHarHttpVersion,
toHarPostData,
toHarQueryString,
checkMimeTypeListAndParseBody,
} from './harUtils';

describe('harUtils', () => {
Expand Down Expand Up @@ -244,6 +245,30 @@ describe('harUtils', () => {
});
});

describe('checkMimeTypeListAndParseBody', () => {
it('should return text if cant parse JSON', () => {
const content = 'Hello!';
const returned = checkMimeTypeListAndParseBody(
['application/json'],
content,
'application/json',
);
expect(returned).toEqual({
mimeType: 'application/json',
text: content,
});
});

it('should parse json if no mimeType is passed and mimeTypeList contains empty string', () => {
const content = '{"test": "hello"}';
const returned = checkMimeTypeListAndParseBody([''], content);
expect(returned).toEqual({
mimeType: undefined,
json: { test: 'hello' },
});
});
});

describe('version', () => {
it('should work with no version', () => {
expect(toHarHttpVersion()).toEqual('HTTP/1.1');
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/har/harUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const fromHarContent = (content?: HarFormatContent) => {
return Buffer.alloc(0);
};

const checkMimeTypeListAndParseBody = (
export const checkMimeTypeListAndParseBody = (
parseMimeTypesAsJson: string[],
body: string | Buffer,
mimeType?: string,
Expand Down

0 comments on commit 5554bc8

Please sign in to comment.