question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Test times out unexpectedly, despite expected behavior otherwise

See original GitHub issue

Hi there, @clavery63 and I have noticed some behavior that we believe is a bug, resulting in tests timing out when they should complete successfully.

I’ve reproduced here https://codesandbox.io/s/suspicious-ardinghelli-0yt2n

import { cold } from "jest-marbles";

describe("timeout error", () => {
  test("times out without completing observable", done => {
    const fakeActions = cold("t|", { t: true });

    fakeActions.subscribe({
      next: value => {
        console.log("value received:", value);
        expect(value).toEqual(true);
      },
      complete: () => {
        console.log("observable complete");
        done();
      }
    });
  });
});

Based on the way the logs appear, and our understanding of the tools involved, we’d expect the test to pass, but instead it times out.

If this is expected behavior, please let us know if you have thoughts on how to go about testing this sort of thing effectively. Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
just-jebcommented, Sep 7, 2019

Please use toSatisfyOnFlush, available since 2.5.0.
Let me know if that helps.

2reactions
just-jebcommented, Sep 7, 2019

Yeah, it seems that testing side effects is currently a bit problematic. I have a few things in mind (such as adding toHaveSideEffect matcher), will see what can be done.
There is a workaround for you until it’s done though. You can pipe to the tested stream and tap your assert:

    const mapStreamWith = (mapper: any) => (stream: any) => stream.pipe(map(mapper));
        const fakeStream = cold("t|");
    const mapSpy = jest.fn().mockReturnValue('r');
    const streamMapper = mapStreamWith(mapSpy);
    const testee = streamMapper(fakeStream).pipe(tap(() => {
      expect(mapSpy.mock.calls.length).toEqual(1);
    }))
    expect(testee).toBeMarble('r|');
Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing-library: avoid these mistakes in async tests
Sometimes, tests start to unexpectedly fail even if no changes were made to the business logic. It may happen after e.g. you updated...
Read more >
For async tests and hooks, ensure "done()" is called
Once rejected done is never called and mocha reports time out. I solved this by writing a .catch block and chaining it with...
Read more >
Test Anxiety (for Teens) - Nemours KidsHealth
Test anxiety is not the same as doing poorly on a certain test because your mind is on something else.
Read more >
Cypress and Flaky Tests: How to Handle Timeout Errors
One such default behavior involves automatically waiting for four seconds (ideally to allow your application to finish whatever operation it may ...
Read more >
Fix program errors and improve code - Visual Studio (Windows)
In this article, find out how Visual Studio can help you find problems in your code using build output, code analysis, debugging tools,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found