How to use the sinon.test function in sinon

To help you get started, we’ve selected a few sinon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Ariel-Rodriguez / react-amp-template / test / spec / amp / index.js View on Github external
import Validator from '../../../lib/utils/ampvalidator';
import { expect } from 'chai';
import sinon from 'sinon';
import AppStatic from '../../mocks/appStatic';

const sx = sinon.sandbox.create();
let validator;
let AppHTML;

describe('AMP Validation', sinon.test(() => {
  before('setup', (done) => {
    Validator.getInstance().then((instance) => {
      validator = instance;
      // warm up validator
      validator.validateMarkup('', true);
    })
    .then(AppStatic.render)
    .then((html) => {
      AppHTML = html;
      done();
    });
  });

  after(() => {
    sx.restore();
  });
github mheap / trello-cli / test / authenticate.js View on Github external
describe('#loadAuthCache()', sinon.test(function() {
        // We use sinon.stub not this.stub to persist across tests
        config = sinon.stub(config, "get")
        config.withArgs('configPath').returns('/tmp/.missing.trello-cli/');
        config.withArgs('authCache').returns('auth.json');
        logger = sinon.mock(logger)

        it('should parse valid JSON file', sinon.test(function() {
            this.stub(Auth.fs, "readFileSync").returns('{}');
            expect(Auth.loadAuthCache()).to.eql({})
        }));

        it('should create empty auth file if none exists', sinon.test(function() {
            this.stub(Auth.fs, "readFileSync").throws()
            logger.expects("debug").withExactArgs('No auth file found: /tmp/.missing.trello-cli/auth.json')
            logger.expects("debug").withExactArgs('Auth file created')

            var spy = this.spy(Auth, "writeAuthFile")

            Auth.loadAuthCache()

            expect(spy).to.have.been.calledOnce;
        }));
    }));
github deliciousinsights / fb-flo-brunch / test / core.js View on Github external
message: 'Yo %s!',
        messageColor: 'green',
        messageLevel: 'debug',
        messageResourceColor: 'red'
      });
      checkUpdate('.debug("%cYo %c%s%c!", "color: green", "color: red", _resourceURL, "color: green")');


      function checkUpdate(str) {
        obj.update.should.be.a('function');
        obj.update.toString().should.include(str);
      }
    });
  });

  it('should not start if disabled', sinon.test(function() {
    var startServer = sinon.stub(Plugin.prototype, 'startServer');
    newWithConfig({ enabled: false });
    startServer.should.not.have.been.called;
  }));

  describe('when starting the server', function() {
    it('should forward all untouched fb-flo options', function() {
      var opts = Plugin.OPTIONS.reduce(function(acc, prop) {
        acc[prop] = 'demo';
        return acc;
      }, {});
      var obj = newWithConfig(opts);
      flo.should.have.been.calledOnce;
      flo.should.have.been.calledWithMatch(
        obj.config.publicPath,
        pick(opts, Plugin.FB_FLO_OPTIONS),
github bitcoinjs / bitcoinjs-lib / test / hdnode.js View on Github external
describe('getAddress', function () {
    var hd

    beforeEach(function () {
      var f = fixtures.valid[0]

      hd = HDNode.fromBase58(f.master.base58, NETWORKS_LIST)
    })

    it('wraps ECPair.getAddress', sinon.test(function () {
      this.mock(hd.keyPair).expects('getAddress')
        .once().returns('foobar')

      assert.strictEqual(hd.getAddress(), 'foobar')
    }))
  })
github Nexmo / nexmo-cli / tests / validator.js View on Github external
describe('due to error codes in response objects', () => {
        it('should emit an error', sinon.test(function() {
          let emitter = new Emitter();
          let validator = new Validator(emitter);

          let stub = this.stub(emitter, 'error');

          validator.response(null, {'error-code' : '500', 'error-code-label' : 'foobar'});

          expect(stub).to.be.called;
          expect(stub).to.be.calledWith('foobar');
        }));

        it('should ignore a 200 status', sinon.test(function() {
          let emitter = new Emitter();
          let validator = new Validator(emitter);

          let stub = this.stub(emitter, 'error');

          validator.response(null, {'error-code' : '200'});

          expect(stub).not.to.be.called;
        }));
      });
github node-red / node-red / test / red / cli / lib / config_spec.js View on Github external
describe("cli config", function() {
    afterEach(function() {
        config.unload();
    });
    it('loads preferences when target referenced', sinon.test(function() {
        this.stub(fs,"readFileSync",function() {
            return '{"target":"http://example.com:1880"}'
        });
        config.target.should.eql("http://example.com:1880");
    }));
    it('provide default value for target', sinon.test(function() {
        this.stub(fs,"readFileSync",function() {
            return '{}'
        });
        config.target.should.eql("http://localhost:1880");
    }));
    it('saves preferences when target set', sinon.test(function() {
        this.stub(fs,"readFileSync",function() {
            return '{"target":"http://another.example.com:1880"}'
        });
        this.stub(fs,"writeFileSync",function() {});
        
        config.target.should.eql("http://another.example.com:1880");
        config.target = "http://final.example.com:1880";
        
        fs.readFileSync.calledOnce.should.be.true;
        fs.writeFileSync.calledOnce.should.be.true;
github js-reporters / js-reporters / test / unit / tap-reporter.js View on Github external
var spy = this.stub(console, 'log')

    emitter.emit('testEnd', data.actualUndefinedTest)

    expect(spy).to.have.been.calledWith('  actual: undefined')
  }))

  it('should output actual value for failed assertions even it was falsy', sinon.test(function () {
    var spy = this.stub(console, 'log')

    emitter.emit('testEnd', data.actualFalsyTest)

    expect(spy).to.have.been.calledWith('  actual: "0"')
  }))

  it('should output expected value for failed assertions even it was undefined', sinon.test(function () {
    var spy = this.stub(console, 'log')

    emitter.emit('testEnd', data.expectedUndefinedTest)

    expect(spy).to.have.been.calledWith('  expected: undefined')
  }))

  it('should output expected value for failed assertions even it was falsy', sinon.test(function () {
    var spy = this.stub(console, 'log')

    emitter.emit('testEnd', data.expectedFalsyTest)

    expect(spy).to.have.been.calledWith('  expected: "0"')
  }))

  it('should output the total number of tests', sinon.test(function () {
github bitcoinjs / bitcoinjs-lib / test / base58check.js View on Github external
describe('base58check', function () {
  var param

  beforeEach(function () {
    param = {}
  })

  it('wraps bs58check.decode', sinon.test(function () {
    var expectation = this.mock(bs58check).expects('decode')
    expectation.once().calledWith(param)
    expectation.onCall(0).returns('foo')

    assert.equal(base58check.decode(param), 'foo')
  }))

  it('wraps bs58check.encode', sinon.test(function () {
    var expectation = this.mock(bs58check).expects('encode')
    expectation.once().calledWith(param)
    expectation.onCall(0).returns('foo')

    assert.equal(base58check.encode(param), 'foo')
  }))
})
github canalplus / react-keys / src / engines / __spec__ / bounds.spec.js View on Github external
it(
      'should return horizontal left if current el left > next el left',
      sinon.test(function() {
        const current = { left: 10 };
        const next = { left: 5 };

        determineGeo(current, next).should.eql({
          horizontal: 'left',
          vertical: 'equal',
        });
      })
    );

    it(
      'should return horizontal right if current el left < next el left',
      sinon.test(function() {
        const current = { left: 5 };
        const next = { left: 10 };

        determineGeo(current, next).should.eql({
          horizontal: 'right',
          vertical: 'equal',
        });
      })
    );

    it(
      'should return horizontal equal if current el left === next el left',
      sinon.test(function() {
        const current = { left: 10 };
        const next = { left: 10 };
github canalplus / react-keys / src / redux / __spec__ / reducer.spec.js View on Github external
describe('RESET_STATE', () => {
    it(
      'should reset state',
      sinon.test(function() {
        const binder = { id: '1', priority: 1 };
        const state = { ...initialKeysSate, binders: [binder] };
        const action = { type: RESET_STATE };
        const result = reducer(state, action);
        result.should.eqls({ ...initialKeysSate });
      })
    );
  });