<commit_before>var Rx = require('../../dist/cjs/Rx');

var AsyncSubject = Rx.AsyncSubject;
var nextTick = Rx.Scheduler.nextTick;
var Observable = Rx.Observable;

describe('AsyncSubject', function () {
  it('should emit the last value when complete', function () {
    var subject = new AsyncSubject();
    var results = [];

    subject.subscribe(function (x) {
      results.push(x);
    }, null, function () {
      results.push('done');
    });

    subject.next(1);
    expect(results).toEqual([]);
    subject.next(2);
    expect(results).toEqual([]);
    subject.complete();
    expect(results).toEqual([2, 'done']);
  });

  it('should emit the last value to subsequent subscriptions after complete', function () {
    var subject = new AsyncSubject();
    var results = [];

    var observer = {
      next: function (x) {
        results.push(x);
      },
      error: null,
      complete: function () {
        results.push('done');
      }
    };
    var subscription = subject.subscribe(observer);

    subject.next(1);
    expect(results).toEqual([]);
    subject.next(2);
    expect(results).toEqual([]);
    subject.complete();
    expect(results).toEqual([2, 'done']);

    subscription.unsubscribe();

    results = [];
    subject.subscribe(observer);
    expect(results).toEqual([2, 'done']);
  });

  it('should just complete if no value has been nexted into it', function () {
    var subject = new AsyncSubject();
    var results = [];

    subject.subscribe(function (x) {
      results.push(x);
    }, null, function () {
      results.push('done');
    });

    expect(results).toEqual([]);
    subject.complete();
    expect(results).toEqual(['done']);
  });

  it('should just complete to any subscription if no value has been nexted into it', function () {
    var subject = new AsyncSubject();
    var results = [];

    var observer = {
      next: function (x) {
        results.push(x);
      },
      error: null,
      complete: function () {
        results.push('done');
      }
    };
    var subscription = subject.subscribe(observer);

    expect(results).toEqual([]);
    subject.complete();
    expect(results).toEqual(['done']);

    subscription.unsubscribe();
    results = [];
    subject.subscribe(observer);
    expect(results).toEqual(['done']);
  });

  it('should only error if an error is passed into it', function () {
    var subject = new AsyncSubject();
    var results = [];

    subject.subscribe(function (x) {
      results.push(x);
    }, function (err) {
      results.push(err);
    }, function () {
      throw 'should not be called';
    });

    subject.next(1);
    expect(results).toEqual([]);
    subject.error(new Error('bad'));
    expect(results).toEqual([new Error('bad')]);
  });

  it('should only error if an error is passed into it', function () {
    var subject = new AsyncSubject();
    var results = [];

    subject.subscribe(function (x) {
      results.push(x);
    }, function (err) {
      results.push(err);
    }, function () {
      throw 'should not be called';
    });

    subject.next(1);
    expect(results).toEqual([]);
    subject.error(new Error('bad'));
    expect(results).toEqual([new Error('bad')]);
  });
});<commit_msg>refactor(AsyncSubject): minor refactor on spec file<commit_after>var Rx = require('../../dist/cjs/Rx');

var AsyncSubject = Rx.AsyncSubject;
var Observable = Rx.Observable;

var TestObserver = function () {
  this.results = [];
};

TestObserver.prototype = {
  next: function (x) { this.results.push(x); },
  error: function (err) { this.results.push(err); },
  complete: function () { this.results.push('done'); }
};

describe('AsyncSubject', function () {
  it('should emit the last value when complete', function () {
    var subject = new AsyncSubject();
    var observer = new TestObserver();
    subject.subscribe(observer);

    subject.next(1);
    expect(observer.results).toEqual([]);
    subject.next(2);
    expect(observer.results).toEqual([]);
    subject.complete();
    expect(observer.results).toEqual([2, 'done']);
  });

  it('should keep emitting the last value to subsequent subscriptions', function () {
    var subject = new AsyncSubject();
    var observer = new TestObserver();
    var subscription = subject.subscribe(observer);

    subject.next(1);
    expect(observer.results).toEqual([]);
    subject.next(2);
    expect(observer.results).toEqual([]);
    subject.complete();
    expect(observer.results).toEqual([2, 'done']);

    subscription.unsubscribe();

    observer.results = [];
    subject.subscribe(observer);
    expect(observer.results).toEqual([2, 'done']);
  });

  it('should just complete if no value has been nexted into it', function () {
    var subject = new AsyncSubject();
    var observer = new TestObserver();
    subject.subscribe(observer);

    expect(observer.results).toEqual([]);
    subject.complete();
    expect(observer.results).toEqual(['done']);
  });

  it('should keep emitting complete to subsequent subscriptions', function () {
    var subject = new AsyncSubject();
    var observer = new TestObserver();
    var subscription = subject.subscribe(observer);

    expect(observer.results).toEqual([]);
    subject.complete();
    expect(observer.results).toEqual(['done']);

    subscription.unsubscribe();
    observer.results = [];
    subject.subscribe(observer);
    expect(observer.results).toEqual(['done']);
  });

  it('should only error if an error is passed into it', function () {
    var subject = new AsyncSubject();
    var observer = new TestObserver();
    subject.subscribe(observer);

    subject.next(1);
    expect(observer.results).toEqual([]);
    subject.error(new Error('bad'));
    expect(observer.results).toEqual([new Error('bad')]);
  });
});
{'fraction_non_alphanumeric': 0.1664352655328011, 'fraction_numerical': 0.0029503644567858383, 'mean_word_length': 3.2879464285714284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '911912', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1609, 'n_words': 388}