-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IsReadableStreamDisturbed predicate
Closes #378.
- Loading branch information
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const test = require('tape-catch'); | ||
|
||
import { IsReadableStreamDisturbed } from '../lib/readable-stream' | ||
|
||
test('IsReadableStreamDisturbed returns true for a stream on which read() has been called', t => { | ||
const rs = new ReadableStream(); | ||
|
||
t.equal(IsReadableStreamDisturbed(rs), false, 'rs should not be disturbed on construction'); | ||
|
||
const reader = rs.getReader(); | ||
t.equal(IsReadableStreamDisturbed(rs), false, | ||
'getReader() call has no effect on whether a stream is disturbed or not'); | ||
|
||
reader.read(); | ||
t.equal(IsReadableStreamDisturbed(rs), true, 'rs should be disturbed after read() call'); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('IsReadableStreamDisturbed returns true for a stream on which cancel() has been called', t => { | ||
const rs = new ReadableStream(); | ||
|
||
t.equal(IsReadableStreamDisturbed(rs), false, 'rs should not be disturbed on construction'); | ||
|
||
const reader = rs.getReader(); | ||
t.equal(IsReadableStreamDisturbed(rs), false, | ||
'getReader() call has no effect on whether a stream is disturbed or not'); | ||
|
||
reader.cancel(); | ||
t.equal(IsReadableStreamDisturbed(rs), true, 'rs should be disturbed after cancel() call'); | ||
|
||
t.end(); | ||
}); |