Skip to content

Instantly share code, notes, and snippets.

@sskanishk
Created February 5, 2021 21:38
Show Gist options
  • Save sskanishk/e39295f57524ba7ce36b62856cfe10fb to your computer and use it in GitHub Desktop.
Save sskanishk/e39295f57524ba7ce36b62856cfe10fb to your computer and use it in GitHub Desktop.
Code 1) Deep Clone
Clone.js
it contaim the deep clone function.
Clone.test.js
it Contain the test case.
Package.json
dependencies for JEST.
To start
node Clone.js
To test
npm install
npm test
const obj = {
name: "Paddy",
address: {
town: "Lerum",
country: "Sweden"
}
}
function deepClone(obj) {
return {...obj}
}
// console.log(deepClone(obj))
module.exports = deepClone;
const deepClone = require('./Clone');
test('checking both are same object ', () => {
const obj = {
name: "Paddy",
address: {
town: "Lerum",
country: "Sweden"
}
}
// checking both are same object
expect(deepClone(obj)).toEqual(obj);
});
test('checking its clone or not just returning same object', () => {
const obj = {
name: "Paddy",
address: {
town: "Lerum",
country: "Sweden"
}
}
// checking its clone or not just returning same object
expect(deepClone(obj)).not.toBe(obj);
});
{
"name": "CloneObject",
"version": "1.0.0",
"description": "",
"main": "Clone.js",
"scripts": {
"test": "jest --coverage"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"jest": "^26.6.3"
}
}
@sskanishk
Copy link
Author

Screenshot 2021-02-06 at 3 27 36 AM
Screenshot 2021-02-06 at 3 29 09 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment