Underscore _.flter test

by david_i_smith

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js"></script>
<script src="https://searls.github.io/jasmine-all/jasmine-all-min.js"></script>

JavaScript

describe('_.filter', function () {
	beforeEach(function () {
  	var self = this;
    this.data = ['John', 'Paul', 'George', 'Ringo'];
  	this.exceptionHandler = function (e) {
    	console.log(e);
    };
    spyOn(this, 'exceptionHandler');
    this.filterData = function (strs, match) {
    	try {
        return _.reject(strs, function (str) {
          return str === match;
        });
      } catch (e) {
      	self.exceptionHandler(e);
      }
    };
    this.test = function () {
      return ;
    };
  });
  it('should return the values in the list without the elements that the truth test passes', function () {
  	expect(this.filterData(this.data, 'Ringo').length).toEqual(3);
  	expect(_.contains(this.filterData(this.data, 'Ringo'), 'Ringo')).toBeFalsy();
  });
  it('should fail silently if an element included in the truth test is not in the list', function () {
  	this.data.pop();
  	expect(this.data.length).toEqual(3);
  	expect(_.contains(this.filterData(this.data, 'Ringo'), 'Ringo')).toBeFalsy();
    expect(this.exceptionHandler).not.toHaveBeenCalled();
  	expect(this.filterData(this.data, 'Ringo').length).toEqual(3);
  });
});