var sortBy = require('./sortBy');

describe('Array/sortBy', function () {
  var people = [
    {name: 'Elena', age: '2'},
    {name: 'George', age: '33'},
    {name: 'Vasiliki', age: '32'},
    {name: 'Vaggelis', age: '30'}
  ];

  it('sorts an array of objects by property', function () {
    expect(sortBy(people, 'name')).toEqual([
      {name: 'Elena', age: '2'},
      {name: 'George', age: '33'},
      {name: 'Vaggelis', age: '30'},
      {name: 'Vasiliki', age: '32'}
    ]);

    expect(sortBy(people, 'name', false)).toEqual([
      {name: 'Vasiliki', age: '32'},
      {name: 'Vaggelis', age: '30'},
      {name: 'George', age: '33'},
      {name: 'Elena', age: '2'}
    ]);

    expect(sortBy(people, 'age', true, function (age) {
      return age * 2;
    })).toEqual([
      {name: 'Elena', age: '2'},
      {name: 'Vaggelis', age: '30'},
      {name: 'Vasiliki', age: '32'},
      {name: 'George', age: '33'}
    ]);

    expect(function () {
      return sortBy({}, 'age');
    }).toThrow();
  });
});

@@ -918,32 +918,459 @@
  '33'%7D%0A    %5D);%0A%0A
+    expect(sortBy(people, 'nonExistentProperty')).toEqual(%5B%0A      %7Bname: 'Elena', age: '2'%7D,%0A      %7Bname: 'George', age: '33'%7D,%0A      %7Bname: 'Vasiliki', age: '32'%7D,%0A      %7Bname: 'Vaggelis', age: '30'%7D%0A    %5D);%0A%0A    expect(sortBy(people, 'nonExistentProperty', false)).toEqual(%5B%0A      %7Bname: 'Elena', age: '2'%7D,%0A      %7Bname: 'George', age: '33'%7D,%0A      %7Bname: 'Vasiliki', age: '32'%7D,%0A      %7Bname: 'Vaggelis', age: '30'%7D%0A    %5D);%0A%0A
     expect(funct

test sorting by a non-existent property