Skip to content

Commit

Permalink
feat: πŸ”₯ Fix snapshot
Browse files Browse the repository at this point in the history
Fix snapshot error. Ensure all thrown errors throw actual errors rather
than strings

βœ… Closes: #220
  • Loading branch information
Ryan Smee committed Apr 5, 2022
1 parent b18c227 commit 42a54d4
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/falso/src/lib/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const objectIsUnique: (
) => boolean = (item: any, items: any[], keys: string[]) => {
for (const key of keys) {
if (!item[key]) {
throw `${key} does not exist in this array value type`;
throw new Error(`${key} does not exist in this array value type`);
}

if (items.some((arrayItem) => arrayItem[key] === item[key])) {
Expand Down
4 changes: 2 additions & 2 deletions packages/falso/src/lib/food.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export function randFood<Options extends FoodOptions = never>(
const origin: string | undefined = options?.origin;

if (!totalOrigins) {
throw 'No foods found';
throw new Error('No foods found');
}

if (origin && !foodData[origin]) {
throw 'No foods found for selected origin';
throw Error('No foods found for selected origin');
}

const factory: () => string = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/falso/src/lib/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function randLine<Options extends LineOptions = never>(
const lineCount: number = options?.lineCount ?? 5;

if (lineCount < 1 || isNaN(lineCount)) {
throw 'Line count must be greater than 0';
throw Error('Line count must be greater than 0');
}

const factory = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/falso/src/lib/sports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function randSports<Options extends SportCategories = never>(
const category: string | undefined = options?.category;

if (!categoriesCount) {
throw 'No Sport Categories found';
throw Error('No Sport Categories found');
}

if (category && !sportsData[category]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/falso/src/lib/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function randText<Options extends TextOptions = never>(
const charCount: number = options?.charCount ?? 10;

if (charCount < 1 || isNaN(charCount)) {
throw 'Character count must be greater than 0';
throw new Error('Character count must be greater than 0');
}

const factory = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`objectIsUnique keys contains a key that doesn't exist should throw error 1`] = `undefined`;
exports[`objectIsUnique keys contains a key that doesn't exist should throw error 1`] = `"noExistentKey does not exist in this array value type"`;

0 comments on commit 42a54d4

Please sign in to comment.