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(); });

Encode string for URL (angular)

HttpParameterCodec : is a codec for encoding and decoding parameters in URLs( Used by HttpParams). If you need to encode Url you can use the below: encodeURI assumes that the input is a complete URI that might have some characters which need encoding in it. encodeURIComponent will encode everything with special meaning, so you use … Read more

Python: FastAPI error 422 with POST request when sending JSON data

Straight from the documentation: The function parameters will be recognized as follows: If the parameter is also declared in the path, it will be used as a path parameter. If the parameter is of a singular type (like int, float, str, bool, etc) it will be interpreted as a query parameter. If the parameter is … Read more

Python sum, why not strings? [closed]

Python tries to discourage you from “summing” strings. You’re supposed to join them: “”.join(list_of_strings) It’s a lot faster, and uses much less memory. A quick benchmark: $ python -m timeit -s ‘import operator; strings = [“a”]*10000’ ‘r = reduce(operator.add, strings)’ 100 loops, best of 3: 8.46 msec per loop $ python -m timeit -s ‘import … Read more

Disable client-side validation in MVC 3 “cancel” submit button

What is this mystical force that causes the answer to reveal itself as soon as you post a question somewhere? It looks like in MVC 3 you disable client-side validation on a button by adding the class “cancel” to it. So in my example: <input type=”submit” name=”backButton” value=”← Back” title=”Go back to step 1.” class=”cancel” … Read more