当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Sinon.stub函数代码示例

本文整理汇总了TypeScript中Sinon.stub函数的典型用法代码示例。如果您正苦于以下问题:TypeScript stub函数的具体用法?TypeScript stub怎么用?TypeScript stub使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了stub函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: beforeEach

 beforeEach(() => {
   getSocketInstance = sinon
     .stub(server, 'getSocketInstance')
     .callsFake(() => socket);
 });
开发者ID:SARAVANA1501,项目名称:nest,代码行数:5,代码来源:server-tcp.spec.ts

示例2: beforeEach

 beforeEach(() => {
   const mockStore = configureStore([thunk, promiseMiddleware()]);
   store = mockStore({});
   axios.get = sinon.stub().returns(Promise.resolve(resolvedObject));
   axios.post = sinon.stub().returns(Promise.resolve(resolvedObject));
 });
开发者ID:gjik911,项目名称:git_01,代码行数:6,代码来源:settings.reducer.spec.ts

示例3: it

 it('should throw "InvalidGrpcPackageException"', () => {
   sinon.stub(server, 'lookupPackage').callsFake(() => null);
   expect(server.bindEvents()).to.eventually.throws(
     InvalidGrpcPackageException,
   );
 });
开发者ID:a1r0,项目名称:nest,代码行数:6,代码来源:server-grpc.spec.ts

示例4: test

    test('process commands on the server', function (done) {
      var
        client = new stratum.Client(),
        server = new stratum.Server(),
        defers = createDefers(6),
        cmd = '{"method":"mining.subscribe","params":[],"id":1}\n{"method":"mining.authorize","params":[],"id":1}\n',
        cmds = stratum.Server.getStratumCommands(new Buffer(cmd))

      sinon.stub(client, 'send')

      server.on('mining', function (req, deferred, socket) {
        expect(socket).to.be(client)
        expect(this).to.be(server)

        if (/authorize|subscribe|set_difficulty/.test(req.method)) {
          defers.next(req.method)
        }
      })

      server.on('mining.error', function (error, socket) {
        expect(socket).to.be(client)
        expect(error).to.match(/Client trying to reach a broadcast function|Stratum request without method or result field|Method not found/)
        defers.next(error.toString())
      })

      stratum.Server.processCommands.call(
        server,
        client,
        cmds.cmds
      )

      stratum.Server.processCommands.call(
        server,
        client,
        stratum.Server.getStratumCommands(new Buffer('{"method":"mining.subscribe","params":[],"id":1}\n')).cmds
      )

      stratum.Server.processCommands.call(
        server,
        client,
        stratum.Server.getStratumCommands(new Buffer('{"method":"mining.invalid","params":[],"id":1}\n')).cmds
      )

      stratum.Server.processCommands.call(
        server,
        client,
        stratum.Server.getStratumCommands(new Buffer('{"method":"mining.set_difficulty","params":[],"id":1}\n')).cmds
      )

      stratum.Server.processCommands.call(
        server,
        client,
        stratum.Server.getStratumCommands(new Buffer('{"jsonrpc":"2.0","params":[],"id":0}')).cmds
      )

      defers.promise.spread(function (err, broadcast, invalid, sub2, authorize, sub1) {
        expect(sub1).to.be('subscribe')
        expect(authorize).to.be('authorize')
        expect(sub2).to.be('subscribe')
        expect(broadcast).to.match(/ Client trying to reach a broadcast function/)
        expect(err).to.match(/Stratum request without method or result field/)
        expect(invalid).to.match(/Method not found/)

        server.removeAllListeners()
        done()
      })
    })
开发者ID:pocesar,项目名称:node-stratum,代码行数:67,代码来源:tests.ts

示例5:

				index: 1,
				option: 'baz',
				selected: true
			});

			widget.expectRender(v('div', {
				'aria-disabled': 'true',
				'aria-selected': null,
				classes: [ css.option ],
				id: 'bar',
				role: 'option',
				onclick: widget.listener
			}, [ 'foo' ]));
		},

		'option click'() {
			const onClick = sinon.stub();
			widget.setProperties({
				label: 'foo',
				id: 'bar',
				index: 1,
				option: 'baz',
				onClick
			});

			widget.sendEvent('click');
			assert.isTrue(onClick.calledWith('baz', 1));
		}
	}
});
开发者ID:bitpshr,项目名称:widgets,代码行数:30,代码来源:ListboxOption.ts

示例6: before

 before(() => {
   Sinon.stub(EndpointRegistry, "useBefore");
 });
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:3,代码来源:useAuth.spec.ts

示例7: describe

  describe("function githubMiddleware()", () => {
    const throwStub = sinon.stub();
    const nextStub = sinon.stub();

    afterEach(() => {
      throwStub.reset();
      nextStub.reset();
    });

    it("continues if event not recognised", () => {
      githubMiddleware(
        {
          request: {
            body: {}
          },
          path: "/",
          throw: throwStub,
          status: 0,
          headers: {
            "X-GitHub-Event": "not a recognised event"
          }
        },
        nextStub.returns(Promise.resolve())
      );

      nextStub.should.have.been.calledOnce;
    });

    it('waits for downstream, resolves once "complete" event is fired', async () => {
      const ctxFixture = {
        request: {
          body: {}
        },
        path: "/",
        throw: throwStub,
        status: 0,
        headers: {
          "X-GitHub-Event": "status"
        },
        body: {
          response: ""
        }
      };

      // This all seems rather convoluted but trust me it works
      const nextPromise = Promise.resolve();
      const resultPromise = githubMiddleware(
        ctxFixture,
        nextStub.returns(nextPromise)
      );

      await nextPromise;
      middlewareEventHandler.emit("complete");

      nextStub.should.have.been.calledOnce;

      const result = await resultPromise;
      ctxFixture.body.response.should.equal("ok");
    });

    xit("returns 500 if anything throws", () => {
      // I don't know how I'd test this
    });
  });
开发者ID:ft-interactive,项目名称:ft-ig-github-project-manager,代码行数:64,代码来源:github.spec.ts

示例8: require

import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import { stub, SinonStub } from 'sinon';
const cs: any = require('cross-spawn');
let spawnStub: SinonStub;
let spawnOnStub: SinonStub;
let npmInstall: any;

registerSuite({
	name: 'npmInstall',
	setup() {
		npmInstall = require('intern/dojo/node!./../../src/npmInstall');
	},
	'beforeEach'() {
		spawnOnStub = stub();
		const spawnOnResponse = {
			'on': spawnOnStub
		};

		spawnOnStub.returns(spawnOnResponse);
		spawnStub = stub(cs, 'spawn').returns(spawnOnResponse);
	},
	'afterEach'() {
		spawnStub.restore();
	},
	async 'Should call spawn to run an npm process'() {
		spawnOnStub.onFirstCall().callsArg(1);
		await npmInstall.default();
		assert.isTrue(spawnStub.calledOnce);
	},
	async 'Should reject with an error when spawn throws an error'() {
开发者ID:dylans,项目名称:cli,代码行数:31,代码来源:npmInstall.ts

示例9: beforeEach

					beforeEach((): void => {
						toucheventproxy.enabled = scenario.enabled;
						event = new MouseEvent("click", {cancelable: scenario.cancelable});
						sinon.stub(event, "stopPropagation");
						toucheventproxy.handleEvent(event);
					});
开发者ID:scottohara,项目名称:tvmanager,代码行数:6,代码来源:toucheventproxy_spec.ts

示例10: describe

import {assert, expect} from "chai";
import * as Proxyquire from "proxyquire";
import * as Sinon from "sinon";
import {FakeResponse} from "../../../../../../test/helper";

const middleware: any = Sinon.stub();
const useAfterStub: any = Sinon.stub().returns(middleware);

const {Redirect} = Proxyquire.load("../../../../src/mvc/decorators/method/redirect", {
  "./useAfter": {UseAfter: useAfterStub}
});

class Test {
}

describe("Redirect", () => {
  describe("with one parameter", () => {
    before(() => {
      this.descriptor = {};
      this.options = "test";
      Redirect(this.options)(Test, "test", this.descriptor);
      this.middleware = useAfterStub.args[0][0];
    });

    after(() => {
      delete this.descriptor;
      delete this.options;
      delete this.middleware;
    });

    it("should create middleware", () => {
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:31,代码来源:redirect.spec.ts

示例11: before

 before(() => {
   this.decorateStub = Sinon.stub(ParamRegistry, "decorate");
   Err();
 });
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:4,代码来源:error.spec.ts

示例12: expected

				h.expect(() => expected({ states }));
			},

			'state classes on label'() {
				let states: States = {
					invalid: true,
					disabled: true,
					readOnly: true,
					required: true
				};
				const h = harness(() => w(EnhancedTextInput, { label: 'foo', ...states }));
				h.expect(() => expected({ label: true, states }));
			},

			'focused class'() {
				const mockMeta = sinon.stub();
				const mockFocusGet = sinon.stub().returns({
					active: false,
					containsFocus: true
				});
				mockMeta.withArgs(Focus).returns({
					get: mockFocusGet
				});
				const h = harness(() => w(MockMetaMixin(EnhancedTextInput, mockMeta), {}));
				h.expect(() => expected({ focused: true }));
			},

			events() {
				const onBlur = sinon.stub();
				const onChange = sinon.stub();
				const onClick = sinon.stub();
开发者ID:mwistrand,项目名称:widgets,代码行数:31,代码来源:EnhancedTextInput.ts

示例13: beforeEach

		beforeEach((): SinonStub => sinon.stub(episodeController, "toggleStatusDateRow" as keyof EpisodeController));
开发者ID:scottohara,项目名称:tvmanager,代码行数:1,代码来源:episode-controller_spec.ts

示例14: it

    it("Should provide access to BindingWhenSyntax methods", () => {

        interface Army {}

        @injectable()
        class Army implements Army {}

        interface ZombieArmy {}

        @injectable()
        class ZombieArmy implements ZombieArmy {}

        interface Ninja {}
        let ninjaIdentifier = "Ninja";

        let binding = new Binding<Ninja>(ninjaIdentifier);
        let bindingWhenOnSyntax = new BindingWhenOnSyntax<Ninja>(binding);

        // cast to any to be able to access private props
        let _bindingWhenOnSyntax: any = bindingWhenOnSyntax;

        // stubs for BindingWhenSyntax methods
        let whenStub = sinon.stub(_bindingWhenOnSyntax._bindingWhenSyntax, "when").returns(null);
        let whenTargetNamedStub = sinon.stub(_bindingWhenOnSyntax._bindingWhenSyntax, "whenTargetNamed").returns(null);
        let whenTargetTaggedStub = sinon.stub(_bindingWhenOnSyntax._bindingWhenSyntax, "whenTargetTagged").returns(null);
        let whenInjectedIntoStub = sinon.stub(_bindingWhenOnSyntax._bindingWhenSyntax, "whenInjectedInto").returns(null);
        let whenParentNamedStub = sinon.stub(_bindingWhenOnSyntax._bindingWhenSyntax, "whenParentNamed").returns(null);
        let whenParentTaggedStub = sinon.stub(_bindingWhenOnSyntax._bindingWhenSyntax, "whenParentTagged").returns(null);

        let whenAnyAncestorIsStub = sinon.stub(
            _bindingWhenOnSyntax._bindingWhenSyntax, "whenAnyAncestorIs").returns(null);

        let whenNoAncestorIsStub = sinon.stub(
            _bindingWhenOnSyntax._bindingWhenSyntax, "whenNoAncestorIs").returns(null);

        let whenAnyAncestorNamedStub = sinon.stub(
            _bindingWhenOnSyntax._bindingWhenSyntax, "whenAnyAncestorNamed").returns(null);

        let whenNoAncestorNamedStub = sinon.stub(
            _bindingWhenOnSyntax._bindingWhenSyntax, "whenNoAncestorNamed").returns(null);

        let whenNoAncestorTaggedStub = sinon.stub(
            _bindingWhenOnSyntax._bindingWhenSyntax, "whenNoAncestorTagged").returns(null);

        let whenAnyAncestorTaggedStub = sinon.stub(
            _bindingWhenOnSyntax._bindingWhenSyntax, "whenAnyAncestorTagged").returns(null);

        let whenAnyAncestorMatchesStub = sinon.stub(
            _bindingWhenOnSyntax._bindingWhenSyntax, "whenAnyAncestorMatches").returns(null);

        let whenNoAncestorMatchesStub = sinon.stub(
            _bindingWhenOnSyntax._bindingWhenSyntax, "whenNoAncestorMatches").returns(null);

        // invoke BindingWhenOnSyntax methods
        bindingWhenOnSyntax.when((request: interfaces.Request) => { return true; });
        bindingWhenOnSyntax.whenTargetNamed("test");
        bindingWhenOnSyntax.whenTargetTagged("test", true);
        bindingWhenOnSyntax.whenInjectedInto("armny");
        bindingWhenOnSyntax.whenInjectedInto(Army);
        bindingWhenOnSyntax.whenParentNamed("test");
        bindingWhenOnSyntax.whenParentTagged("test", true);
        bindingWhenOnSyntax.whenAnyAncestorIs(Army);
        bindingWhenOnSyntax.whenNoAncestorIs(ZombieArmy);
        bindingWhenOnSyntax.whenAnyAncestorNamed("test");
        bindingWhenOnSyntax.whenAnyAncestorTagged("test", true);
        bindingWhenOnSyntax.whenNoAncestorNamed("test");
        bindingWhenOnSyntax.whenNoAncestorTagged("test", true);
        bindingWhenOnSyntax.whenAnyAncestorMatches((request: interfaces.Request) => { return true; });
        bindingWhenOnSyntax.whenNoAncestorMatches((request: interfaces.Request) => { return true; });

        // assert invoked BindingWhenSyntax methods
        expect(whenStub.callCount).eql(1);
        expect(whenTargetNamedStub.callCount).eql(1);
        expect(whenTargetTaggedStub.callCount).eql(1);
        expect(whenInjectedIntoStub.callCount).eql(2);
        expect(whenParentNamedStub.callCount).eql(1);
        expect(whenParentTaggedStub.callCount).eql(1);
        expect(whenAnyAncestorIsStub.callCount).eql(1);
        expect(whenNoAncestorIsStub.callCount).eql(1);
        expect(whenAnyAncestorNamedStub.callCount).eql(1);
        expect(whenAnyAncestorTaggedStub.callCount).eql(1);
        expect(whenNoAncestorNamedStub.callCount).eql(1);
        expect(whenNoAncestorTaggedStub.callCount).eql(1);
        expect(whenAnyAncestorMatchesStub.callCount).eql(1);
        expect(whenNoAncestorMatchesStub.callCount).eql(1);

    });
开发者ID:Aciho,项目名称:InversifyJS,代码行数:87,代码来源:binding_when_on_syntax.test.ts

示例15: beforeEach

 beforeEach(() => {
   existsStub = sinon.stub(instance, 'exists');
   createStub = sinon.stub(instance, 'create').returns(peerLogicStub);
 });
开发者ID:RiseVision,项目名称:rise-node,代码行数:4,代码来源:peers.spec.ts


注:本文中的Sinon.stub函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。