mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:07:45 +00:00
LibJS: Add an Iterator constructor and object
The Iterator object cannot be constructed directly but can be subclassed or created with `Iterator.from` (not implemented here).
This commit is contained in:
parent
428109e709
commit
5736b53013
9 changed files with 165 additions and 1 deletions
27
Userland/Libraries/LibJS/Tests/builtins/Iterator/Iterator.js
Normal file
27
Userland/Libraries/LibJS/Tests/builtins/Iterator/Iterator.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
describe("errors", () => {
|
||||
test("called without new", () => {
|
||||
expect(() => {
|
||||
Iterator();
|
||||
}).toThrowWithMessage(TypeError, "Iterator constructor must be called with 'new'");
|
||||
});
|
||||
|
||||
test("cannot be directly constructed", () => {
|
||||
expect(() => {
|
||||
new Iterator();
|
||||
}).toThrowWithMessage(TypeError, "Abstract class Iterator cannot be constructed directly");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("length is 0", () => {
|
||||
expect(Iterator).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("can be constructed from with subclass", () => {
|
||||
class TestIterator extends Iterator {}
|
||||
|
||||
const iterator = new TestIterator();
|
||||
expect(iterator).toBeInstanceOf(TestIterator);
|
||||
expect(iterator).toBeInstanceOf(Iterator);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue