Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to TDD with jest #58

Open
jimmythecode opened this issue Jun 1, 2022 · 1 comment
Open

Trying to TDD with jest #58

jimmythecode opened this issue Jun 1, 2022 · 1 comment
Assignees

Comments

@jimmythecode
Copy link

Is your feature request related to a problem? Please describe.
I'm trying to test as I develop with jest.

Describe the solution you'd like
A working example would be really helpful

Describe alternatives you've considered
I've tried to figure it out myself. I got as far as the following code, but I get the Jest has detected the following 1 open handle potentially keeping Jest from exiting: error:

import { SubmissionStream } from "snoostorm";
import { redditApiClientInfo } from "./redditApi";

let submissionStream: SubmissionStream;
beforeAll(() => {
    submissionStream = new SubmissionStream(redditApiClientInfo, {
        subreddit: "malefashionadvice",
        pollTime: 1000, // runs every 1 seconds
        limit: 2,
    });
});

afterAll(async () => {
   return submissionStream.end()
});

export async function getLatestWaywtPost(submissionStream: SubmissionStream) {
    let submissionsCount = 0;
    submissionStream.on("item", async submission => {
        console.log(submission);
        submissionsCount ++;
    })
    if(submissionsCount === 2){
        console.log("ending stream, count:", submissionsCount);
        return submissionsCount;
    }
}

test("getLatestWaywtPost()", async () => {
    const latestPostLength = await getLatestWaywtPost(submissionStream)
    await new Promise((r) => setTimeout(r, 2000));
    expect(latestPostLength).toBe(2)
});

Additional context
N/A

@brenapp
Copy link
Owner

brenapp commented Aug 1, 2022

Related to #59, currently there is no way for you to handle exceptions encountered, but it wouldn't be too difficult to add. I will add it to my todo list :-)

@brenapp brenapp self-assigned this Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants