How to use the sinon.match 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 segmentstream / digital-data-manager / test / DigitalDataEnricher.spec.js View on Github external
]
        }
      })

      // +2 quantity
      assert.ok(eventsSpy.calledWith(sinon.match({
        name: 'Added Product',
        category: 'Ecommerce',
        product: {
          id: '1'
        },
        quantity: 2
      })))

      // +1 new item
      assert.ok(eventsSpy.calledWith(sinon.match({
        name: 'Added Product',
        category: 'Ecommerce',
        product: {
          id: '2'
        },
        quantity: 1
      })))

      // -3 items
      assert.ok(eventsSpy.calledWith(sinon.match({
        name: 'Removed Product',
        category: 'Ecommerce',
        product: {
          id: '3'
        },
        quantity: 3
github jshint / jshint / tests / cli.js View on Github external
var dir = __dirname + "/../examples/";
    var rep = require("../examples/reporter.js");
    var config = {
      "asi": true,
      "overrides": {
        "bar.js": {
          "asi": false
        }
      }
    };

    this.sinon.stub(process, "cwd").returns(dir);
    this.sinon.stub(rep, "reporter");
    this.sinon.stub(shjs, "cat")
      .withArgs(sinon.match(/foo\.js$/)).returns("a()")
      .withArgs(sinon.match(/bar\.js$/)).returns("a()")
      .withArgs(sinon.match(/config\.json$/))
        .returns(JSON.stringify(config));

    this.sinon.stub(shjs, "test")
      .withArgs("-e", sinon.match(/foo\.js$/)).returns(true)
      .withArgs("-e", sinon.match(/bar\.js$/)).returns(true)
      .withArgs("-e", sinon.match(/config\.json$/)).returns(true);

    cli.exit.withArgs(0).returns(true)
      .withArgs(1).throws("ProcessExit");

    // Test successful file
    cli.interpret([
      "node", "jshint", "foo.js", "--config", "config.json", "--reporter", "reporter.js"
    ]);
    test.ok(rep.reporter.args[0][0].length === 0);
github jacobrosenthal / react-native-ble / test / abstract / test-bindings-abstract.js View on Github external
it('should emit valueRead', function() {
      var eventSpy = sandbox.spy();
      bindings.once('valueRead', eventSpy);

      if (typeof setup == 'function')
        setup(mock, sandbox);

      var bufferMatcher = sinon.match.instanceOf(Buffer).and(sinon.match(function(val) {
        return val.toString() === a.dataBuffer.toString();
      }));

      bindings.readValue(a.peripheralUuidString, a.serviceUuidString, a.characteristicUuidString, a.descriptorUuidString);
      eventSpy.calledWith(a.peripheralUuidString, a.serviceUuidString, a.characteristicUuidString, a.descriptorUuidString, bufferMatcher).should.equal(true);
    });
github hexojs / hexo / test / scripts / console / list_post.js View on Github external
.then(() => {
        listPosts();
        expect(console.log.calledWith(sinon.match('Date'))).to.be.true;
        expect(console.log.calledWith(sinon.match('Title'))).to.be.true;
        expect(console.log.calledWith(sinon.match('Path'))).to.be.true;
        expect(console.log.calledWith(sinon.match('Category'))).to.be.true;
        expect(console.log.calledWith(sinon.match('Tags'))).to.be.true;
        for (let i = 0; i < posts.length; i++) {
          expect(console.log.calledWith(sinon.match(posts[i].source))).to.be.true;
          expect(console.log.calledWith(sinon.match(posts[i].slug))).to.be.true;
          expect(console.log.calledWith(sinon.match(posts[i].title))).to.be.true;
        }
      });
  });
github elastic / kibana / src / legacy / plugin_discovery / plugin_config / __tests__ / extend_config_service.js View on Github external
it('calls logDeprecation() with deprecation messages', async () => {
      const config = Config.withDefaultSchema();
      const logDeprecation = sinon.stub();
      await extendConfigService(pluginSpec, config, {
        foo: {
          bar: {
            baz: {
              oldTest: '123'
            }
          }
        }
      }, logDeprecation);
      sinon.assert.calledOnce(logDeprecation);
      sinon.assert.calledWithExactly(logDeprecation, sinon.match('"oldTest" is deprecated'));
    });
github gm0t / react-sticky-el / test / unit / sticky.js View on Github external
it('should listen for scroll event on scrollElement', function () {
      const { sticky, unmount } = mountSticky({ scrollElement: "#scrollarea" });

      expect(listen).have.been.calledWithMatch(
        match(el => el === document.getElementById('scrollarea'), 'div#scrollarea'),
        createMatch(['scroll']),
        match(cb => cb === sticky.instance().checkPosition, 'this.checkPosition')
      );
      unmount();
    });
  });
github brendonboshell / supercrawler / test / Crawler.spec.js View on Github external
var numCrawlsOfUrl = function (url, followRedirect) {
    var numCalls = 0;
    var n = 0;
    var call;

    while (requestSpy.getCall(n)) {
      call = requestSpy.getCall(n);

      if (call.calledWith(sinon.match({
        url: url,
        forever: true,
        followRedirect: followRedirect
      }))) {
        numCalls++;
      }

      n++;
    }

    return numCalls;
  };
github elastic / kibana / x-pack / legacy / plugins / security / server / routes / api / v1 / __tests__ / authenticate.js View on Github external
beforeEach(() => {
      samlAcsRoute = serverStub.route
        .withArgs(sinon.match({ path: '/api/security/v1/saml' }))
        .firstCall
        .args[0];

      request = requestFixture({ payload: { SAMLResponse: 'saml-response-xml' } });
    });
github walmartlabs / lumbar / test / plugins / amd.js View on Github external
function(err, resources) {
          fs.readFile.should.have.been.calledWith(sinon.match(/foo\/js\/foo\/foo.js/));
          fs.readFile.should.have.been.calledWith(sinon.match(/foo\/js\/bar.js/));
          fs.readFile.should.have.been.calledWith(sinon.match(/foo\/js\/views\/baz.js/));

          resources.should.eql([{amd: 'foo/js/views/baz.js'}, {amd: 'foo/js/bar.js'}, {amd: 'foo/js/foo/foo.js'}]);
          done();
        });
    });
github OverloadUT / alexa-plex / test / main.js View on Github external
beforeEach(function(){
                plexAPIStubs.query.withArgs('/').resolves(require('./samples/root.json'));
                plexAPIStubs.query.withArgs(sinon.match(/\/library\/metadata\/[0-9]+$/))
                    .resolves(require('./samples/library_metadata_item.json'));
                plexAPIStubs.query.withArgs('/library/sections/1/all')
                    .resolves(require('./samples/library_section_allshows.json'));
                plexAPIStubs.query.withArgs('/library/metadata/1/allLeaves')
                    .resolves(require('./samples/library_metadata_showepisodes_withunwatched.json'));
                plexAPIStubs.query.withArgs('/library/metadata/143/allLeaves')
                    .resolves(require('./samples/library_metadata_showepisodes_allwatched.json'));

                plexAPIStubs.postQuery.withArgs(sinon.match(/\/playQueues/))
                    .resolves(require('./samples/playqueues.json'));

                plexAPIStubs.perform.withArgs(sinon.match(/\/playMedia/))
                    .resolves(null, true);

                plexAPIStubs.find.withArgs('/clients')
                    .resolves(require('./samples/clients.json'));
            });