beforeEach(() => { getSocketInstance = sinon .stub(server, 'getSocketInstance') .callsFake(() => socket); });
beforeEach(() => { const mockStore = configureStore([thunk, promiseMiddleware()]); store = mockStore({}); axios.get = sinon.stub().returns(Promise.resolve(resolvedObject)); axios.post = sinon.stub().returns(Promise.resolve(resolvedObject)); });
it('should throw "InvalidGrpcPackageException"', () => { sinon.stub(server, 'lookupPackage').callsFake(() => null); expect(server.bindEvents()).to.eventually.throws( InvalidGrpcPackageException, ); });
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() }) })
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)); } } });
before(() => { Sinon.stub(EndpointRegistry, "useBefore"); });
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 }); });
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'() {
beforeEach((): void => { toucheventproxy.enabled = scenario.enabled; event = new MouseEvent("click", {cancelable: scenario.cancelable}); sinon.stub(event, "stopPropagation"); toucheventproxy.handleEvent(event); });
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", () => {