Skip to content

Commit

Permalink
test: Update tests to handle error cases with neverthrow
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki3jp committed Jan 28, 2025
1 parent f1e3c5a commit e3aa037
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
6 changes: 5 additions & 1 deletion tests/playlist-item.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ test("playlistItemFrom", () => {

for (const [input, expected] of dummy) {
const actual = playlistItemFrom(input, logger);
expect(actual.data).toEqual(expected);
if (actual.isErr()) {
expect(actual.error).toEqual(expected);
} else {
expect(actual.value).toEqual(expected);
}
}
});
7 changes: 6 additions & 1 deletion tests/playlist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ test("Playlist#from", () => {
];

for (const [data, expected] of dummy) {
expect(Playlist.from(data, logger).data).toEqual(expected);
const actual = Playlist.from(data, logger);
if (actual.isErr()) {
expect(actual.error).toEqual(expected);
} else {
expect(actual.value).toEqual(expected);
}
}
});
7 changes: 6 additions & 1 deletion tests/privacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ test("convertToPrivacy", () => {
];

for (const [data, expected] of dummy) {
expect(convertToPrivacy(data).data).toEqual(expected);
const actual = convertToPrivacy(data);
if (actual.isErr()) {
expect(actual.error).toEqual(expected);
} else {
expect(actual.value).toEqual(expected);
}
}
});
7 changes: 6 additions & 1 deletion tests/thumbnails.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,12 @@ describe("Thumbnails", () => {

test(`Thumbnails#from for ${dummy.length} cases`, () => {
for (const [data, expected] of dummy) {
expect(Thumbnails.from(data, logger).data).toEqual(expected);
const actual = Thumbnails.from(data, logger);
if (actual.isErr()) {
expect(actual.error).toEqual(expected);
} else {
expect(actual.value).toEqual(expected);
}
}
});
});

0 comments on commit e3aa037

Please sign in to comment.