Closed BramComyn closed 1 month ago
This code is located in src/turtle-downloader
and test/unit/turtle-downloader
and currently only on the use-cases branch
Mock the thing that creates the request?
That already happens in the beforeEach
of my test:
request = new EventEmitter() as any;
request.close = jest.fn();
requester = {
addRequestEventHandler: jest.fn(),
connectAndRequest: jest.fn().mockReturnValue(request),
} as any;
I also tried mocking the implementation to call request.emit(event)
there, but this connectAndRequest
-method is also called before the handler is set, so probably, I should re-evaluate how I can set this handler and achieve the functionality I desire to.
You can also mock on
🙃
Woops
I am writing this issue, because I have spend a long time trying to figure out how to be able to test the
download
-method of my use caseTurtleDownloader
. In my last two tests I do this:or
The problem is that inside the
download
-method, I await a promise that rejects or resolves based on what event gets triggered first:However, I have no possibility to trigger the event being fired, because the listener is only attached in this promise and neither my test, nor that function will continue executing when this promise has not been resolved. I am trying to figure out how I can do this, but haven't found any clues in the jest documentation or other people's issues.