本文整理汇总了TypeScript中Sinon.SinonSpy类的典型用法代码示例。如果您正苦于以下问题:TypeScript SinonSpy类的具体用法?TypeScript SinonSpy怎么用?TypeScript SinonSpy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SinonSpy类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("Sets the game name if it is allowed", () => {
const spy: SinonSpy = sinon.spy();
element.element.value = allowedName;
subscribe(channel, spy);
expect(nameInput(element)).to.equal(allowedName);
expect(spy.calledWith(allowedName)).to.equal(true);
});
示例2: describe
describe('applyHeaders', () => {
let normalizeSpy: SinonSpy;
let updateSpy: SinonSpy;
beforeEach(() => {
normalizeSpy = sinon.spy(instance, 'normalize');
updateSpy = sinon.spy(instance, 'update');
});
afterEach(() => {
normalizeSpy.restore();
updateSpy.restore();
});
it('should call normalize and update', () => {
const retVal = instance.applyHeaders(undefined);
expect(retVal).to.deep.equal({ port: 0, state: 1 });
expect(normalizeSpy.called).to.be.true;
expect(updateSpy.calledOnce).to.be.true;
});
it('should return headers', () => {
const header = { something: 'header' };
const retVal = instance.applyHeaders(header as any);
expect(retVal).to.deep.equal({ port: 0, state: 1, something: 'header' });
expect(normalizeSpy.called).to.be.true;
expect(updateSpy.calledOnce).to.be.true;
});
});
示例3: cleanSpy
export function cleanSpy(spy: SinonSpy) {
if (spy) {
if (spy.restore) {
spy.restore();
}
spy.reset();
}
}
示例4: it
it('should return unmuted dappIds array in peer obj without height', () => {
const expectedPeer = {
broadhash: '',
clock : '',
dappid : ['dappId', 'dappId2'],
height : '',
ip : '127.0.0.1',
nonce : '',
os : '',
port : 1010,
state : 2,
updated : '',
version : '',
};
peer.dappid = ['dappId', 'dappId2'];
const normalized = instance.normalize(Object.assign({}, peer));
expect(parseIntSpy.calledTwice).to.be.true;
expect(parseIntSpy.firstCall.args.length).to.equal(2);
expect(parseIntSpy.firstCall.args[0]).to.equal(peer.port);
expect(parseIntSpy.firstCall.args[1]).to.equal(0);
expect(parseIntSpy.getCall(1).args.length).to.equal(2);
expect(parseIntSpy.getCall(1).args[0]).to.equal(peer.state);
expect(parseIntSpy.getCall(1).args[1]).to.equal(PeerState.DISCONNECTED);
expect(normalized).to.deep.equal(expectedPeer);
});
示例5: expect
.then(([result, response, descriptor]) => {
// promise results
expect(result).to.be.instanceof(FragmentResult);
expect(result.data).to.deep.equal([{ id: 1, name: 'FOO JOE' }]);
expect(response).to.have.all.keys([
'code',
'config',
'data',
'headers',
'request',
'status',
'statusText'
]);
expect(descriptor).to.equal(spyStore_touchResource.getCall(0).args[0]);
// hooks
expect(spyMutableUsers_generateDescriptor.callCount).to.equal(1);
expect(spyStore_touchResource.callCount).to.equal(1);
expect(spyStore_touchResource.getCall(0).args[0]).to.deep.match(expectedDescriptor);
expect(spyStore_updateResource.callCount).to.equal(1);
expect(spyStore_updateResource.getCall(0).args[1]).to.deep.equal({
id: responseData.id,
name: responseData.name.toUpperCase()
});
expect(spyStore_destroyResource.callCount).to.equal(0);
}, () => {
示例6: useFakeClock
useFakeClock(clock=>{
cache.get({
numAsString:"5"
});
clock.tick(100);
assert.equal(fetch.getCall(0).args[1], 25, "first static dependency passed in correctly");
assert.equal(fetch.getCall(0).args[2], 3, "second static dependency passed in correctly");
});
示例7: onReadySpy
const mockOn = (event: string, cb: (err?: string) => void) => {
if (!doError && event === 'ready') {
onReadySpy();
cb();
} else if (doError && event === 'error') {
onErrorSpy();
cb('testError');
}
};
示例8: it
it('should invoke default handler when none specified', () => {
const descriptor = new ResourceDescriptor(null, IActionType.get, schema.users.__stack);
processResponse(descriptor, dataCollectionUsers);
expect(spy_defaultHandler.callCount).to.equal(1);
expect(spy_defaultHandler.getCall(0).args[0]).to.equal(descriptor);
expect(spy_defaultHandler.getCall(0).args[1]).to.equal(dataCollectionUsers);
});