subscription.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import assert from 'assert';
  2. import { testMethodProperty } from './properties.js';
  3. describe('subscription', () => {
  4. function getSubscription(subscriber = () => {}) {
  5. return new Observable(subscriber).subscribe();
  6. }
  7. describe('unsubscribe', () => {
  8. it('is a method on Subscription.prototype', () => {
  9. let subscription = getSubscription();
  10. testMethodProperty(Object.getPrototypeOf(subscription), 'unsubscribe', {
  11. configurable: true,
  12. writable: true,
  13. length: 0,
  14. });
  15. });
  16. it('reports an error if the cleanup function throws', () => {
  17. let error = {};
  18. let subscription = getSubscription(() => {
  19. return () => { throw error };
  20. });
  21. subscription.unsubscribe();
  22. assert.equal(hostError, error);
  23. });
  24. });
  25. describe('closed', () => {
  26. it('is a getter on Subscription.prototype', () => {
  27. let subscription = getSubscription();
  28. testMethodProperty(Object.getPrototypeOf(subscription), 'closed', {
  29. configurable: true,
  30. writable: true,
  31. get: true,
  32. });
  33. });
  34. });
  35. });