"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _cachePreviousArgs = _interopRequireDefault(require("../cachePreviousArgs"));

describe('cachePreviousArgs', function () {
  var stub = sinon.stub();
  var x = {
    value: 1
  };
  var y = {
    value: 2
  };

  var fn = function fn(x, y) {
    stub();
    return x.value + y.value;
  };

  var cachedFn;
  beforeEach(function () {
    cachedFn = (0, _cachePreviousArgs.default)(fn);
  });
  afterEach(function () {
    stub.resetHistory();
  });
  it('returns the value of the original function', function () {
    expect(cachedFn(x, y)).to.eq(3);
  });
  it('caches the function when the arguments are the same', function () {
    expect(cachedFn(x, y)).to.eq(3);
    expect(cachedFn(x, y)).to.eq(3);
    expect(stub.callCount).to.eq(1);
  });
  it('does not cache the function when one of the args is different', function () {
    expect(cachedFn(x, y)).to.eq(3);
    expect(cachedFn(x, {
      value: 4
    })).to.eq(5);
    expect(stub.callCount).to.eq(2);
  });
});