pg-mem
pg-mem copied to clipboard
pg-mem doesn't seem to work in conjunction with sinon fake timers
Describe the bug
I am trying to run a test that uses a fake timer in order to reliably check the output. The query works just fine without fake timers, but when I do:
const initialExpiration = new Date();
sinon.useFakeTimers(initialExpiration);
The query never returns and my test times out.
To Reproduce
SELECT count(*) FROM my_table WHERE owner=$1 and object_type=$2 and code IS NOT NULL;
pg-mem version
2.0.1
Thanks a lot for taking the time to support this project, it's very helpful!
Found a workaround for this. sinon allows you to only fake some of the methods so I used this form:
sinon.useFakeTimers({ now: initialExpiration, toFake: ['Date'] });
I guess pg-mem relies on some of the other date related functions somewhere and this allows us to avoid it. Further information: https://sinonjs.org/releases/latest/fake-timers/
Still happening with 2.1.9.