How do you debug Jasmine tests with Resharper?

Since I didn’t got debugger; to work I found another solution. By adding the following to my test, resharper won’t be notified that the test has finished so we can set debug breakpoints in the opened browser (I use chrome) and update (F5) the page. jasmine.getEnv().currentRunner_.finishCallback = function () {}; Since Jasmine 2.0 you need … Read more

How do I test an error on reading from a request body?

You may create and use an http.Request forged by you, which deliberately returns an error when reading its body. You don’t necessarily need a whole new request, a faulty body is enough (which is an io.ReadCloser). Simplest achieved by using the httptest.NewRequest() function where you can pass an io.Reader value which will be used (wrapped … Read more

How to test Spring @EventListener method?

First, As you’re using Spring Boot, the testing of these becomes pretty straightforward. This test will spin up the boot context and inject a real instance of ApplicationEventPublisher, but create a mocked instance of SomeDependency. The test publishes the desired event, and verifies that your mock was invoked as you expected. @RunWith(SpringRunner.class) @SpringBootTest public class … Read more

How to test method call order with Moq

I recently created Moq.Sequences which provides the ability to check ordering in Moq. You may want to read my post that describes the following: Supports method invocations, property setters and getters. Allows you to specify the number of times a specific call should be expected. Provides loops which allow you to group calls into a … Read more

Advice on Mocking System Calls

In this case you don’t need to mock getaddrinfo, rather, you need to test without relying on its functionality. Both Patrick and Noah have good points but you have at least two other options: Option 1: Subclass to Test Since you already have your object in a class, you can subclass to test. For example, … Read more

stubbing a function using jest

With jest you should use jest.spyOn: jest .spyOn(jQuery, “ajax”) .mockImplementation(({ success }) => success([ 1, 2, 3 ])); Full example: const spy = jest.fn(); const payload = [1, 2, 3]; jest .spyOn(jQuery, “ajax”) .mockImplementation(({ success }) => success(payload)); jQuery.ajax({ url: “https://example.api”, success: data => spy(data) }); expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledWith(payload); You can try live example on codesandbox: … Read more