How to use the sinon.mock 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 apifytech / apify-js / test / actor.js View on Github external
const testMain = async ({ userFunc, exitCode }) => {
    // Mock process.exit() to check exit code and prevent process exit
    const processMock = sinon.mock(process);
    const exitExpectation = processMock
        .expects('exit')
        .withExactArgs(exitCode)
        .once()
        .returns();

    let error = null;

    try {
        await Promise.resolve()
            .then(() => {
                return new Promise((resolve, reject) => {
                    // Invoke main() function, the promise resolves after the user function is run
                    Apify.main(() => {
                        try {
                            // Wait for all tasks in Node.js event loop to finish
github ozzyogkush / formation / tests / event-handlers / body-events-handler.js View on Github external
it('does nothing when the event key is not a space or enter button', function() {
      const bodyEventsHandler = bodyEventsHandlerStamp({body : document.body});
      const bodyEventsHandlerMock = sinon.mock(bodyEventsHandler);
      const target = document.createElement('input');
      const targetMock = sinon.mock(target);

      const testHandler = e => { bodyEventsHandler.bodyKeyUpHandler(e); };
      document.body.appendChild(target);
      document.body.addEventListener(bodyEventsHandler.getKeyUpEventName(), testHandler);

      bodyEventsHandlerMock.expects('elementIsCustomRadioOrCheckboxWidget').never();
      targetMock.expects('click').never();

      const keyUpEvent = new KeyboardEvent(bodyEventsHandler.getKeyUpEventName(), { bubbles: true, 'key': 'tab' });
      target.dispatchEvent(keyUpEvent);

      bodyEventsHandlerMock.verify();
      targetMock.verify();
github jiripudil / Naja / tests / Naja.HistoryHandler.js View on Github external
it('replays request on popstate if it had uiCache disabled', () => {
			const naja = mockNaja({
				historyHandler: HistoryHandler,
			});
			naja.initialize();

			const mock = sinon.mock(naja);
			mock.expects('makeRequest').withExactArgs(
				'GET',
				'/HistoryHandler/popStateWithoutCache',
				null,
				{
					history: false,
					historyUiCache: false,
				},
			).once();

			window.dispatchEvent(createPopStateEvent({
				href: '/HistoryHandler/popStateWithoutCache',
				ui: false,
			}));

			cleanPopstateListener(naja.historyHandler);
github ozzyogkush / formation / tests / rules / checkbox-default-rules.js View on Github external
it('returns true', function () {
          let $checkbox = $('<input checked="checked" id="test1" name="test" type="checkbox">');
          let $checkboxContainer = $('<div data-fv-min-selected="1" data-fv-group-container="test"></div>');
          let $checkboxMock = sinon.mock($checkbox);
          let $checkboxContainerMock = sinon.mock($checkboxContainer);

          checkboxRulesSetMock.expects('getAttributeOwner').once()
            .withArgs($checkbox).returns($checkboxContainer);
          $checkboxContainerMock.expects('attr').once().withArgs('data-fv-min-selected').returns('1');
          checkboxRulesSetMock.expects('getAllCheckboxesOrRadiosByName')
            .once().withArgs($checkbox)
            .returns($checkbox);
          assert.isTrue(checkboxRulesSet.dataFvMinSelected($checkbox, 'data-fv-min-selected'));

          $checkboxMock.verify();
          $checkboxContainerMock.verify();
          checkboxRulesSetMock.verify();
        });
      });
github mosaicdao / mosaic.js / test / EIP20Gateway / constructor.js View on Github external
it('should throw an error when getEIP20Gateway returns undefined object', async () => {
    mockGetContract = sinon.mock(
      Contracts.getEIP20Gateway(web3, gatewayAddress),
    );

    setup();

    mockedGatewayObject = undefined;
    const errorMessage = `Could not load EIP20Gateway contract for: ${gatewayAddress}`;

    assert.throws(() => {
      new EIP20Gateway(web3, gatewayAddress);
    }, errorMessage);

    SpyAssert.assert(spyContract, 1, [[web3, gatewayAddress]]);

    tearDown();
  });
github kehitysto / coaching-chatbot / test / ut / chatbot / chatbot-service-tests.js View on Github external
it('should call dialog with the supplied arguments', function() {
      const sessionId = 123;
      const context = {};
      const text = 'beef';

      const mockSessions = sinon.mock(this.sessions);
      mockSessions.expects('read')
        .withArgs(sessionId)
        .returns(Promise.resolve({}));

      const mockDialog = sinon.mock(this.dialog);
      mockDialog.expects('run')
        .withArgs(sessionId, context, text)
        .returns({});

      return expect(this.bot.receive(sessionId, text))
        .to.eventually.be.fulfilled
        .then(() => {
          return mockDialog.verify();
        });
    });
github jiripudil / Naja / tests / Naja.FormsHandler.js View on Github external
it('accepts local netteForms reference', () => {
		sinon.spy(window.Nette, 'initForm');
		const mock = sinon.mock(netteForms);
		mock.expects('initForm').once();
		mock.expects('validateForm').once().returns(false);

		const form = document.createElement('form');
		const element = document.createElement('input');
		form.appendChild(element);
		document.body.appendChild(form);

		const naja = mockNaja({
			formsHandler: FormsHandler,
			snippetHandler: SnippetHandler,
		});
		naja.formsHandler.netteForms = netteForms;
		naja.initialize();

		assert.equal(window.Nette.initForm.callCount, 0);
github LiskHQ / lisk-desktop / test / components / delegates / vote.spec.js View on Github external
beforeEach(() => {
      deffered = $q.defer();
      delegateApiMock.expects('vote').returns(deffered.promise);
      dilaogServiceMock = sinon.mock(controller.dialog);
    });
github deepstreamIO / deepstream.io-client-js / test / mocks.ts View on Github external
    getSocket: (): any => ({ socket, socketMock: mock(socket) }),
    connection,
github jamesseanwright / react-animation-frame / test / AnimationFrameComponentTests.jsx View on Github external
beforeEach(function () {
        mockComponent = sinon.mock(InnerComponent.prototype);
        createDom();
    });