Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

add tests for arrCopy #2120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions 38 __tests__/utils/arrCopy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, it, expect } from '@jest/globals';
import arrCopy from '../../src/utils/arrCopy';

describe('arrCopy', () => {
it('should copy an array without offset', () => {
const arr = [1, 2, 3, 4];
const result = arrCopy(arr);
expect(result).toEqual([1, 2, 3, 4]);
expect(result).not.toBe(arr); // Should be a new array
});

it('should copy an array with offset', () => {
const arr = [1, 2, 3, 4, 5];
const result = arrCopy(arr, 2);
expect(result).toEqual([3, 4, 5]);
});

it('should return an empty array if offset >= arr.length', () => {
const arr = [1, 2, 3];
expect(arrCopy(arr, 3)).toEqual([]);
expect(arrCopy(arr, 5)).toEqual([]);
});

it('should handle empty array', () => {
expect(arrCopy([])).toEqual([]);
expect(arrCopy([], 2)).toEqual([]);
});

it('should copy array of objects by reference', () => {
const obj1 = { a: 1 };
const obj2 = { b: 2 };
const arr = [obj1, obj2];
const result = arrCopy(arr);
expect(result).toEqual([obj1, obj2]);
expect(result[0]).toBe(obj1);
expect(result[1]).toBe(obj2);
});
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.