Skip to content

Commit

Permalink
test: use it.each
Browse files Browse the repository at this point in the history
  • Loading branch information
mic-web committed Apr 22, 2024
1 parent 302b216 commit f20e94b
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,16 @@ describe('localeCompareStrings', () => {
});

describe('firstIfSingle', () => {
it('returns null for empty arrays', () => {
expect(firstIfSingle([])).toEqual(null);
});

it('returns single element of an array', () => {
expect(firstIfSingle([1])).toEqual(1);
});

it('returns null for arrays with multiple elements', () => {
expect(firstIfSingle([1, 2])).toEqual(null);
});

it('returns first element for arrays with multiple elements if the first element is null', () => {
expect(firstIfSingle([null, 2])).toEqual(null);
});
it.each([
[[], null],
[[1], 1],
[[null, 2], null],
[[null], null],
[[undefined], undefined],
])(
'returns first element of an array if the array has only one item',
(input, expectedResult) => {
expect(firstIfSingle(input)).toEqual(expectedResult);
},
);
});

0 comments on commit f20e94b

Please sign in to comment.