Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
How can I test func with params that return a object?

I want to test a function that returns a object with given parameters. How can I test it ? Func.js

const functions = {
  createUserWithParams: (firstname, lastname) => ({
    firstname,
    lastname
  })
}

export default functions;

func-test.js

test('should be create a user with params', () => {
  expect(functions.createUserWithParams()).toStrictEqual({firstName: 'John', lastname: 'Travery'})
});

I know the test is wrong, How can I test it successfully ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

functions is an object. so you'll need to use key createUserWithParams to access the function definition in your test and don't forget to pass the parameters

test('should be create a user with params', () => {
  expect(functions['createUserWithParams']('John', 'Travery')).toStrictEqual({firstName: 'John', lastname: 'Travery'})
});

test('should be create a user with params', () => {
  expect(functions.createUserWithParams('John', 'Travery')).toStrictEqual({firstName: 'John', lastname: 'Travery'})
});

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda