Iterator.js 817 B

123456789101112131415161718192021222324252627
  1. describe("errors", () => {
  2. test("called without new", () => {
  3. expect(() => {
  4. Iterator();
  5. }).toThrowWithMessage(TypeError, "Iterator constructor must be called with 'new'");
  6. });
  7. test("cannot be directly constructed", () => {
  8. expect(() => {
  9. new Iterator();
  10. }).toThrowWithMessage(TypeError, "Abstract class Iterator cannot be constructed directly");
  11. });
  12. });
  13. describe("normal behavior", () => {
  14. test("length is 0", () => {
  15. expect(Iterator).toHaveLength(0);
  16. });
  17. test("can be constructed from with subclass", () => {
  18. class TestIterator extends Iterator {}
  19. const iterator = new TestIterator();
  20. expect(iterator).toBeInstanceOf(TestIterator);
  21. expect(iterator).toBeInstanceOf(Iterator);
  22. });
  23. });