<commit_before>import * as Rx from '../../dist/cjs/Rx';
declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions};
import {DoneSignature} from '../helpers/test-helper';

const Observable = Rx.Observable;

/** @test {publish} */
describe('Observable.prototype.publish', () => {
  asDiagram('publish')('should mirror a simple source Observable', () => {
    const source = cold('--1-2---3-4--5-|');
    const sourceSubs =  '^              !';
    const published = source.publish();
    const expected =    '--1-2---3-4--5-|';

    expectObservable(published).toBe(expected);
    expectSubscriptions(source.subscriptions).toBe(sourceSubs);

    published.connect();
  });

  it('To match RxJS 4 behavior, it should NOT allow you to reconnect by subscribing again', (done: DoneSignature) => {
    const expected = [1, 2, 3, 4];
    let i = 0;

    const source = Observable.of(1, 2, 3, 4).publish();

    source.subscribe((x: number) => {
      expect(x).toBe(expected[i++]);
    }, (x) => {
      done.fail('should not be called');
    }, () => {
      source.subscribe((x: any) => {
        done.fail('should not be called');
      }, (x) => {
        done.fail('should not be called');
      }, () => {
        done();
      });

      source.connect();
    });

    source.connect();
  });

  it('should return a ConnectableObservable', () => {
    const source = Observable.of(1).publish();
    expect(source instanceof Rx.ConnectableObservable).toBe(true);
  });

  it('should do nothing if connect is not called, despite subscriptions', () => {<commit_msg>test(Subject): fix tests to appropriately assert ObjectUnsubscribedErrors<commit_after>import * as Rx from '../../dist/cjs/Rx';
declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions};
import {DoneSignature} from '../helpers/test-helper';

const Observable = Rx.Observable;

/** @test {publish} */
describe('Observable.prototype.publish', () => {
  asDiagram('publish')('should mirror a simple source Observable', () => {
    const source = cold('--1-2---3-4--5-|');
    const sourceSubs =  '^              !';
    const published = source.publish();
    const expected =    '--1-2---3-4--5-|';

    expectObservable(published).toBe(expected);
    expectSubscriptions(source.subscriptions).toBe(sourceSubs);

    published.connect();
  });

  it('To match RxJS 4 behavior, it should NOT allow you to reconnect by subscribing again', (done: DoneSignature) => {
    const expected = [1, 2, 3, 4];
    let i = 0;

    const source = Observable.of(1, 2, 3, 4).publish();

    source.subscribe((x: number) => {
      expect(x).toBe(expected[i++]);
    }, (x) => {
      done.fail('should not be called');
    }, () => {
      source.subscribe((x: any) => {
        done.fail('should not be called');
      }, (x) => {
        done.fail('should not be called');
      }, () => {
        done();
      });

      source.connect();
    });

    expect(() => source.connect()).toThrow(new Rx.ObjectUnsubscribedError());
  });

  it('should return a ConnectableObservable', () => {
    const source = Observable.of(1).publish();
    expect(source instanceof Rx.ConnectableObservable).toBe(true);
  });

  it('should do nothing if connect is not called, despite subscriptions', () => {
{'fraction_non_alphanumeric': 0.18184596577017115, 'fraction_numerical': 0.012836185819070905, 'mean_word_length': 3.0407407407407407, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '338203', 'n_tokens_mistral': 1019, 'n_tokens_neox': 968, 'n_words': 240}