Skip to content

Commit

Permalink
fix: matcherToArray should return a copy of the array (#1609)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpbl committed Nov 20, 2022
1 parent 120fb1d commit baf9f34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Expand Up @@ -10,8 +10,11 @@ describe('when a Matcher is passed in', () => {
});

describe('when an array of Matchers is passed in', () => {
test('should return the array', () => {
expect(matcherToArray([matcher])).toStrictEqual([matcher]);
test('should return a copy of the array', () => {
const value = [matcher, matcher];
const result = matcherToArray(value);
expect(result).toStrictEqual(value);
expect(result).not.toBe(value);
});
});

Expand Down
Expand Up @@ -5,7 +5,7 @@ export function matcherToArray(
matcher: Matcher | Matcher[] | undefined
): Matcher[] {
if (Array.isArray(matcher)) {
return matcher;
return [...matcher];
} else if (matcher !== undefined) {
return [matcher];
} else {
Expand Down

0 comments on commit baf9f34

Please sign in to comment.