{"size": 916, "ext": "js", "max_stars_repo_path": "tests/enabled.spec.js", "max_stars_repo_name": "krasimir/bit.js", "max_stars_repo_stars_event_min_datetime": "2015-08-10T17:34:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-19T06:24:49.000Z", "max_issues_repo_path": "tests/enabled.spec.js", "max_issues_repo_name": "krasimir/bit.js", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/enabled.spec.js", "max_forks_repo_name": "krasimir/bit.js", "max_forks_repo_forks_event_min_datetime": "2018-05-22T08:06:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-02T13:18:30.000Z"}
{"max_stars_count": 13, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 21.3023255814, "max_line_length": 70, "alphanum_fraction": 0.5218340611}
var chai = require('chai');
var sinon = require('sinon');
chai.use(require('sinon-chai'));

var expect = chai.expect;

describe('Given Function.prototype.enabled', function() {

  before(function () {
    require('../build/bit');
  });

  describe('when enabled is used', function () {

    it('should disable and enable a function execution', function () {
      var spy = sinon.spy();
      var f = function () { spy(); return f; }.enabled(false);
      f();
      f();
      f.enabled(true);
      f();
      f();
      f();
      f.enabled(false);
      f();
      f();
      expect(spy.callCount).to.be.equal(3);
    });

    it('should allow chaining', function () {
      var spy = sinon.spy();
      var f = function () { spy(); return f; }.enabled(false);
      f();
      f();
      f.enabled(true)()()().enabled(false);
      f();
      f();
      expect(spy.callCount).to.be.equal(3);
    });

  });

});