本文整理汇总了TypeScript中Sinon.stub函数的典型用法代码示例。如果您正苦于以下问题:TypeScript stub函数的具体用法?TypeScript stub怎么用?TypeScript stub使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stub函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: beforeEach
beforeEach(() => {
getSocketInstance = sinon
.stub(server, 'getSocketInstance')
.callsFake(() => socket);
});
示例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));
});
示例3: it
it('should throw "InvalidGrpcPackageException"', () => {
sinon.stub(server, 'lookupPackage').callsFake(() => null);
expect(server.bindEvents()).to.eventually.throws(
InvalidGrpcPackageException,
);
});
示例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()
})
})
示例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));
}
}
});
示例6: before
before(() => {
Sinon.stub(EndpointRegistry, "useBefore");
});
示例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
});
});
示例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'() {
示例9: beforeEach
beforeEach((): void => {
toucheventproxy.enabled = scenario.enabled;
event = new MouseEvent("click", {cancelable: scenario.cancelable});
sinon.stub(event, "stopPropagation");
toucheventproxy.handleEvent(event);
});
示例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", () => {
示例11: before
before(() => {
this.decorateStub = Sinon.stub(ParamRegistry, "decorate");
Err();
});
示例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();
示例13: beforeEach
beforeEach((): SinonStub => sinon.stub(episodeController, "toggleStatusDateRow" as keyof EpisodeController));
示例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);
});
示例15: beforeEach
beforeEach(() => {
existsStub = sinon.stub(instance, 'exists');
createStub = sinon.stub(instance, 'create').returns(peerLogicStub);
});