Question: how to mock with jest
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 4.3k
- Forks
- 299
- Avg merge
- 16h 19m
- Merged PRs (30d)
- 1
Description
Although this is for tracing bugs, since my question is specific to csv-parser I thought maybe it's the right place to ask. (hope you don't mind)
I have the following code to parse csv files:
const records = [];
const parser = fs
.createReadStream(`${process.cwd()}/${file.destination}/${file.filename}`)
.pipe(parse({}));
for await (const record of parser) {
records.push(record);
}
I wanted to know how to mock this code in unit tests with jest. Any idea would be appreciated.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository file or test is named in the issue. Start with the shown createReadStream(...).pipe(parse({})) entry point and determine how the Jest unit test should isolate it; done means a repeatable unit test can supply mocked stream/parser behavior and verify the collected records.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, typescript
- Domain
- testing-qa
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100