feat: add test for onLine throw error (#4542)

This commit is contained in:
Joe Previte 2021-11-22 20:18:58 +00:00 committed by GitHub
parent 0bc96989c2
commit 65d7420ee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -447,6 +447,28 @@ describe("onLine", () => {
expect(await received).toEqual(expected) expect(await received).toEqual(expected)
}) })
describe("used with a process missing stdout ", () => {
it("should throw an error", async () => {
// Initialize a process that does not have stdout.
// "If the child was spawned with stdio set to anything
// other than 'pipe', then subprocess.stdout will be null."
// Source: https://stackoverflow.com/a/46024006/3015595
// Other source: https://nodejs.org/api/child_process.html#child_process_subprocess_stdout
// NOTE@jsjoeio - I'm not sure if this actually happens though
// which is why I have to set proc.stdout = null
// a couple lines below.
const proc = cp.spawn("node", [], {
stdio: "ignore",
})
const mockCallback = jest.fn()
expect(() => util.onLine(proc, mockCallback)).toThrowError(/stdout/)
// Cleanup
proc?.kill()
})
})
}) })
describe("escapeHtml", () => { describe("escapeHtml", () => {