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

596
Views
Spyon method in jest - Cannot spyOn on a primitive value
const onSubmitClick = async () => {
var { isSuccess, result } = await callDispatch();
if (isSuccess) {
setValidStatus(true);
}
};

async function callDispatch() {
const result = call to server;
let isSuccess = result.success || (result.response && result.response.data.success);
return { isSuccess, result };
}

and in my test file

 import { EnterPin } from '../pages/enter-pin';
 jest.spyOn(EnterPin.prototype, 'callDispatch').mockImplementation(() =>{
  return 'true'
})
var button  = screen.getByRole('button');
fireEvent.click(button);

but i am getting Cannot spyOn on a primitive value; undefined given I tried below too but it didnot work

jest.spyOn(EnterPin.prototype, 'callDispatch').mockImplementation(() =>{
  return 'true'
})
var button  = screen.getByRole('button');
fireEvent.click(button);
about 4 years ago · Juan Pablo Isaza
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!