Syntax previewClick to edit
1234
export default function shallowClone(value) {
throw new Error('Not implemented');
}
Syntax previewClick to edit
12345678910111213141516171819202122232425
import shallowClone from './file';
describe('shallowClone', () => {
test('clones arrays shallowly', () => {
const arr = [1, { x: 2 }];
const copy = shallowClone(arr);
expect(copy).toEqual(arr);
expect(copy === arr).toBe(false);
expect(copy[1]).toBe(arr[1]);
});
test('clones objects shallowly', () => {
const obj = { a: 1, b: { c: 2 } };
const copy = shallowClone(obj);
expect(copy).toEqual(obj);
expect(copy === obj).toBe(false);
expect(copy.b).toBe(obj.b);
});
test('throws for non-object/array', () => {
expect(() => shallowClone(42)).toThrow(TypeError);
expect(() => shallowClone('x')).toThrow(TypeError);
});
});
Run tests to see results.