How do I stub new Date() using sinon?

I suspect you want the useFakeTimers function: var now = new Date(); var clock = sinon.useFakeTimers(now.getTime()); //assertions clock.restore(); This is plain JS. A working TypeScript/JavaScript example: var now = new Date(); beforeEach(() => { sandbox = sinon.sandbox.create(); clock = sinon.useFakeTimers(now.getTime()); }); afterEach(() => { sandbox.restore(); clock.restore(); });

How do I stub things in MiniTest?

# Create a mock object book = MiniTest::Mock.new # Set the mock to expect :title, return “War and Piece” # (note that unless we call book.verify, minitest will # not check that :title was called) book.expect :title, “War and Piece” # Stub Book.new to return the mock object # (only within the scope of the …

Read more

How to stub process.env in node.js?

From my understanding of process.env, you can simply treat it like any other variable when setting its properties. Keep in mind, though, that every value in process.env must be a string. So, if you need a particular value in your test: it(‘does something interesting’, () => { process.env.NODE_ENV = ‘test’; // … }); To avoid …

Read more

Access restriction on class due to restriction on required library rt.jar?

There’s another solution that also works. Go to the Build Path settings in the project properties. Remove the JRE System Library Add it back; Select “Add Library” and select the JRE System Library. The default worked for me. This works because you have multiple classes in different jar files. Removing and re-adding the JRE lib …

Read more

What’s the difference between a mock & stub?

Foreword There are several definitions of objects, that are not real. The general term is test double. This term encompasses: dummy, fake, stub, mock. Reference According to Martin Fowler’s article: Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists. Fake objects actually have working implementations, but …

Read more