Skip to content

Instantly share code, notes, and snippets.

@dexfs
Last active April 7, 2021 23:52
Show Gist options
  • Select an option

  • Save dexfs/4128cfbba4c61f31c09fb784abb8c1df to your computer and use it in GitHub Desktop.

Select an option

Save dexfs/4128cfbba4c61f31c09fb784abb8c1df to your computer and use it in GitHub Desktop.
Utilizando cloneDeep pois o javascript utliza shallow copy (copiando apenas o primeiro nível do objeto), spread e Object.assign() fazem dessa forma, o que tiver nested é passado por referência.
module.exports = {
name: "name",
nested: {
email: 'user@domain.com.br',
name: 'fulano de tal',
},
}
const Sut = require('@source/index')
const mock = require('./mocks/base-individual-quotation')
const cloneDeep = require('lodash.clonedeep');
describe('Testando', () => {
it('should be defined', async () => {
const sut = new Sut()
expect(sut).toBeDefined()
})
it('should', async () => {
const params = cloneDeep(mock)
const sut = new Sut()
sut.update(params)
})
it('should2', async () => {
const params = cloneDeep(mock)
console.log('params2', params)
const sut = new Sut()
sut.update(params)
})
});
class Test {
update(params) {
params.name = 'teste'
params.nested.name = 'olá ô loquinho'
}
}
module.exports = Test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment