constructor.js 1018 B

123456789101112131415161718192021222324252627282930313233343536
  1. import assert from 'assert';
  2. import { testMethodProperty } from './properties.js';
  3. describe('constructor', () => {
  4. it('throws if called as a function', () => {
  5. assert.throws(() => Observable(() => {}));
  6. assert.throws(() => Observable.call({}, () => {}));
  7. });
  8. it('throws if the argument is not callable', () => {
  9. assert.throws(() => new Observable({}));
  10. assert.throws(() => new Observable());
  11. assert.throws(() => new Observable(1));
  12. assert.throws(() => new Observable('string'));
  13. });
  14. it('accepts a function argument', () => {
  15. let result = new Observable(() => {});
  16. assert.ok(result instanceof Observable);
  17. });
  18. it('is the value of Observable.prototype.constructor', () => {
  19. testMethodProperty(Observable.prototype, 'constructor', {
  20. configurable: true,
  21. writable: true,
  22. length: 1,
  23. });
  24. });
  25. it('does not call the subscriber function', () => {
  26. let called = 0;
  27. new Observable(() => { called++ });
  28. assert.equal(called, 0);
  29. });
  30. });