While Jest: spyOn is listening on a method, other test also calls the listening method and causes the test to fail

method to be tested

   

question

  1. does the result prove that Test 2 during monitoring the k method, if other tests also call k , they will also be logged, so they are called twice, causing the test to fail?
  2. but if I swap Test 1 and Test 2 to ok again, why?
  3. is there a way for Test 1 and Test 2 to be executed in Synchronize? So there will be no problem

Thank you, big shot ~

Mar.05,2022

1. According to the code execution process, listening is executed at the beginning, followed by test 1 of 100ms, and then test 2 calls the sum.k (), of a 200ms, so the toBeCalledTimes after callback should be equal to 2
2. I don't know whether it is because the time of settimeout is not long enough
3, I think it is effective for promise to use async await to wait for asynchronism, but whether it is effective for settimeout to be tested

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be7627-31893.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be7627-31893.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?