Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!