/* globals describe, it, expect, hot, cold, expectObservable, expectSubscriptions */
var Rx = require('../../dist/cjs/Rx.KitchenSink');
var Observable = Rx.Observable;

describe('Observable.prototype.elementAt', function () {
  it('should return first element by zero-based index', function () {
    var source = hot('--a--b--c--|');
    var subs =       '^ !';
    var expected =   '--(a|)';

    expectObservable(source.elementAt(0)).toBe(expected);
    expectSubscriptions(source.subscriptions).toBe(subs);
  });

  it('should return non-first element by zero-based index', function () {
    var source = hot('--a--b--c--d--e--f--|');
    var subs =       '^          !';
    var expected =   '-----------(d|)';

    expectObservable(source.elementAt(3)).toBe(expected);
    expectSubscriptions(source.subscriptions).toBe(subs);
  });

  it('should return last element by zero-based index', function () {
    var source = hot('--a--b--c--|');
    var subs =       '^       !';
    var expected =   '--------(c|)';

    expectObservable(source.elementAt(2)).toBe(expected);
    expectSubscriptions(source.subscriptions).toBe(subs);
  });

  it('should throw if index is smaller than zero', function () {
    expect(function () { Observable.range(0,10).elementAt(-1); })
      .toThrow(new Rx.ArgumentOutOfRangeError());
  });

  it('should raise error if index is out of range but does not have default value', function () {
    var source = hot('--a--|');
    var subs =       '^    !';
    var expected =   '-----#';

    expectObservable(source.elementAt(3))
      .toBe(expected, null, new Rx.ArgumentOutOfRangeError());
    expectSubscriptions(source.subscriptions).toBe(subs);
  });

  it('should return default value if index is out of range', function () {
    var source = hot('--a--|');
    var subs =       '^    !';
    var expected =   '-----(x|)';
    var defaultValue = '42';

    expectObservable(source.elementAt(3, defaultValue)).toBe(expected, { x: defaultValue });
    expectSubscriptions(source.subscriptions).toBe(subs);
  });
});
@@ -1126,32 +1126,919 @@
 e(subs);%0A  %7D);%0A%0A
+  it('should raise error if source is Empty Observable', function () %7B%0A    var source = cold('%7C');%0A    var subs =        '(%5E!)';%0A    var expected =    '#';%0A%0A    expectObservable(source.elementAt(0)).toBe(expected, undefined, new Rx.ArgumentOutOfRangeError());%0A    expectSubscriptions(source.subscriptions).toBe(subs);%0A  %7D);%0A%0A  it('should propagate error if source is Throw Observable', function () %7B%0A    var source = cold('#');%0A    var subs =        '(%5E!)';%0A    var expected =    '#';%0A%0A    expectObservable(source.elementAt(0)).toBe(expected);%0A    expectSubscriptions(source.subscriptions).toBe(subs);%0A  %7D);%0A%0A  it('should return Never if source is Never Observable', function () %7B%0A    var source = cold('-');%0A    var subs =        '%5E';%0A    var expected =    '-';%0A%0A    expectObservable(source.elementAt(0)).toBe(expected);%0A    expectSubscriptions(source.subscriptions).toBe(subs);%0A  %7D);%0A%0A
   it('should thr

add never/empty/throw test cases