本文整理汇总了TypeScript中Sinon.assert.calledOnce方法的典型用法代码示例。如果您正苦于以下问题:TypeScript assert.calledOnce方法的具体用法?TypeScript assert.calledOnce怎么用?TypeScript assert.calledOnce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sinon.assert
的用法示例。
在下文中一共展示了assert.calledOnce方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('writes documents in bulk to the index', async () => {
const index = '.myalias';
const callCluster = sinon.stub();
const docs = [
{
_id: 'niceguy:fredrogers',
_source: {
type: 'niceguy',
niceguy: {
aka: 'Mr Rogers',
},
quotes: ['The greatest gift you ever give is your honest self.'],
},
},
{
_id: 'badguy:rickygervais',
_source: {
type: 'badguy',
badguy: {
aka: 'Dominic Badguy',
},
migrationVersion: { badguy: '2.3.4' },
},
},
];
callCluster.returns(
Promise.resolve({
items: [],
})
);
await Index.write(callCluster, index, docs);
sinon.assert.calledOnce(callCluster);
expect(callCluster.args[0]).toMatchSnapshot();
});
示例2: it
it('fails if new access token is rejected after successful refresh', async () => {
const request = requestFixture();
callWithRequest
.withArgs(sinon.match({ headers: { authorization: 'Bearer foo' } }), 'shield.authenticate')
.rejects({ statusCode: 401 });
callWithInternalUser
.withArgs('shield.getAccessToken', {
body: { grant_type: 'refresh_token', refresh_token: 'bar' },
})
.resolves({ access_token: 'newfoo', refresh_token: 'newbar' });
const authenticationError = new errors.AuthenticationException('Some error');
callWithRequest
.withArgs(
sinon.match({ headers: { authorization: 'Bearer newfoo' } }),
'shield.authenticate'
)
.rejects(authenticationError);
const accessToken = 'foo';
const refreshToken = 'bar';
const authenticationResult = await provider.authenticate(request, {
accessToken,
refreshToken,
});
sinon.assert.calledTwice(callWithRequest);
sinon.assert.calledOnce(callWithInternalUser);
expect(request.headers).not.toHaveProperty('authorization');
expect(authenticationResult.failed()).toBe(true);
expect(authenticationResult.user).toBeUndefined();
expect(authenticationResult.state).toBeUndefined();
expect(authenticationResult.error).toEqual(authenticationError);
});
示例3: it
it('should allow disposing the engine, stopping reusability', function(done) {
const sandbox = sinon.createSandbox();
const spy = sandbox.spy();
type NiceSources = {
other: Stream<string>;
};
type NiceSinks = {
other: Stream<string>;
};
function app(sources: NiceSources): NiceSinks {
return {
other: sources.other.mapTo('a').debug(spy),
};
}
let sinkCompleted = 0;
function driver(sink: Stream<string>) {
sink.addListener({
complete: () => {
sinkCompleted++;
},
});
return xs.of('b');
}
const engine = setupReusable<NiceSources, NiceSinks>({other: driver});
engine.run(app(engine.sources));
sinon.assert.calledOnce(spy);
sinon.assert.calledWithExactly(spy, 'a');
sandbox.restore();
engine.dispose();
assert.strictEqual(sinkCompleted, 1);
done();
});
示例4: test
test('fails if any document fails', async () => {
const index = '.myalias';
const callCluster = sinon.stub();
const docs = [
{
_id: 'niceguy:fredrogers',
_source: {
type: 'niceguy',
niceguy: {
aka: 'Mr Rogers',
},
},
},
];
callCluster.returns(
Promise.resolve({
items: [{ index: { error: { type: 'shazm', reason: 'dern' } } }],
})
);
await expect(Index.write(callCluster, index, docs)).rejects.toThrow(/dern/);
sinon.assert.calledOnce(callCluster);
});
示例5: test
test('creates the task manager index', async () => {
const callCluster = sinon.spy();
const store = new TaskStore({
callCluster,
index: 'tasky',
maxAttempts: 2,
supportedTypes: ['a', 'b', 'c'],
});
await store.init();
sinon.assert.calledOnce(callCluster);
sinon.assert.calledWithMatch(callCluster, 'indices.putTemplate', {
body: {
index_patterns: ['tasky'],
settings: {
number_of_shards: 1,
auto_expand_replicas: '0-1',
},
},
name: 'tasky',
});
});
示例6: it
it('clears session if it belongs to not configured provider.', async () => {
// Add `kbn-xsrf` header to the raw part of the request to make `can_redirect_request`
// think that it's AJAX request and redirect logic shouldn't be triggered.
const systemAPIRequest = requestFixture({
headers: { xCustomHeader: 'xxx', 'kbn-xsrf': 'xsrf' },
});
const notSystemAPIRequest = requestFixture({
headers: { xCustomHeader: 'yyy', 'kbn-xsrf': 'xsrf' },
});
session.get.withArgs(systemAPIRequest).resolves({
state: { accessToken: 'some old token' },
provider: 'token',
});
session.get.withArgs(notSystemAPIRequest).resolves({
state: { accessToken: 'some old token' },
provider: 'token',
});
session.clear.resolves();
server.plugins.kibana.systemApi.isSystemApiRequest
.withArgs(systemAPIRequest)
.returns(true)
.withArgs(notSystemAPIRequest)
.returns(false);
const systemAPIAuthenticationResult = await authenticate(systemAPIRequest);
expect(systemAPIAuthenticationResult.notHandled()).toBe(true);
sinon.assert.calledOnce(session.clear);
const notSystemAPIAuthenticationResult = await authenticate(notSystemAPIRequest);
expect(notSystemAPIAuthenticationResult.notHandled()).toBe(true);
sinon.assert.calledTwice(session.clear);
});
示例7: it
it('calls connected when client connects', () => {
assert.calledOnce(connected);
});
示例8: setTimeout
setTimeout(() => {
sinon.assert.calledOnce(disposeSpy)
sandbox.restore()
done()
})
示例9: setTimeout
setTimeout(() => {
sinon.assert.calledOnce(callback);
sinon.assert.calledOnce(callback2);
done();
}, 1);