Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Commit

Permalink
Fix readJsonObjectFile test
Browse files Browse the repository at this point in the history
  • Loading branch information
rekmarks committed May 12, 2021
1 parent aceedd7 commit 86ec0ec
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,15 @@ describe('readJsonObjectFile', () => {

it('throws an error if the file parses to a falsy value', async () => {
const path = 'arbitrary/path';

jest
.spyOn(fs.promises, 'readFile')
.mockImplementationOnce(async () => 'null')
.mockImplementationOnce(async () => '[]')
.mockImplementationOnce(async () => 'foobar')
.mockImplementationOnce(async () => 'true')
.mockImplementationOnce(async () => 'false');

await expect(readJsonObjectFile(path)).rejects.toThrow(
/non-object value\.$/u,
);
const readFileMock = jest.spyOn(fs.promises, 'readFile');
const badJsonValues = ['null', '[]', '"foobar"', 'true', 'false', '2'];

for (const badValue of badJsonValues) {
readFileMock.mockImplementationOnce(async () => badValue);
await expect(readJsonObjectFile(path)).rejects.toThrow(
/non-object value\.$/u,
);
}
});
});

Expand Down

0 comments on commit 86ec0ec

Please sign in to comment.