本文整理匯總了TypeScript中Sinon.assert.calledTwice方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript assert.calledTwice方法的具體用法?TypeScript assert.calledTwice怎麽用?TypeScript assert.calledTwice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sinon.assert
的用法示例。
在下文中一共展示了assert.calledTwice方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('calls each registered getter once each call', async () => {
const authScope = new AuthScopeService();
const user = {} as any;
const request = requestFixture();
const getter1 = sinon.stub();
const getter2 = sinon.stub();
const getter3 = sinon.stub();
authScope.registerGetter(getter1);
authScope.registerGetter(getter2);
authScope.registerGetter(getter3);
await authScope.getForRequestAndUser(request, user);
sinon.assert.calledOnce(getter1);
sinon.assert.calledOnce(getter2);
sinon.assert.calledOnce(getter3);
await authScope.getForRequestAndUser(request, user);
sinon.assert.calledTwice(getter1);
sinon.assert.calledTwice(getter2);
sinon.assert.calledTwice(getter3);
await authScope.getForRequestAndUser(request, user);
sinon.assert.calledThrice(getter1);
sinon.assert.calledThrice(getter2);
sinon.assert.calledThrice(getter3);
});
示例2: it
it('predicates are called with the same context and proper arguments', function () {
const exampleContext = {some: 'context'},
structure = {
key0: sinon.stub().returns(true),
key1: sinon.stub().returns(true)
},
exampleObject = {
key0: 1,
key1: 'string'
};
const extraArgs = [2, 3];
const args = [exampleObject, ...extraArgs];
isValidStructure.call(exampleContext, structure, ...args);
isValidStructure(structure).call(exampleContext, ...args);
sinon.assert.calledTwice(structure.key0);
sinon.assert.calledTwice(structure.key1);
sinon.assert.alwaysCalledOn(structure.key0, exampleContext);
sinon.assert.alwaysCalledOn(structure.key1, exampleContext);
sinon.assert.calledWith(structure.key0, 1, ...extraArgs);
sinon.assert.calledWith(structure.key1, 'string', ...extraArgs);
});
示例3: it
it('fails if call to delete refresh token responds with an error', async () => {
const request = requestFixture();
const accessToken = 'foo';
const refreshToken = 'bar';
callWithInternalUser
.withArgs('shield.deleteAccessToken', { body: { token: accessToken } })
.returns({ invalidated_tokens: 1 });
const failureReason = new Error('failed to delete token');
callWithInternalUser
.withArgs('shield.deleteAccessToken', { body: { refresh_token: refreshToken } })
.rejects(failureReason);
const authenticationResult = await provider.deauthenticate(request, {
accessToken,
refreshToken,
});
sinon.assert.calledTwice(callWithInternalUser);
sinon.assert.calledWithExactly(callWithInternalUser, 'shield.deleteAccessToken', {
body: { refresh_token: refreshToken },
});
expect(authenticationResult.failed()).toBe(true);
expect(authenticationResult.error).toBe(failureReason);
});
示例4: test
test('waits for isMigrated, if there is an index conflict', async () => {
const log = logStub();
const pollInterval = 1;
const runMigration = sinon.spy(() => {
throw { body: { error: { index: '.foo', type: 'resource_already_exists_exception' } } };
});
const isMigrated = sinon.stub();
isMigrated
.onFirstCall()
.returns(Promise.resolve(false))
.onSecondCall()
.returns(Promise.resolve(true));
await coordinateMigration({
log,
runMigration,
pollInterval,
isMigrated,
});
sinon.assert.calledOnce(runMigration);
sinon.assert.calledTwice(isMigrated);
const warnings = log.warning.args.filter((msg: any) => /deleting index \.foo/.test(msg));
expect(warnings.length).toEqual(1);
});
示例5: it
it("should return false otherwise",sinon.test(function(){
let isActiveStub = this.stub(utilities, "isActive", () => { return false });
let result = utilities.checkExtensionType();
sinon.assert.calledTwice(isActiveStub);
expect(result).to.equal(false);
expect(utilities.getExtensionType()).to.equal(Constants.ExtensionConstants.NO_EXTENSION);
}));
示例6: test
test('creates the task manager index', async () => {
const callCluster = sinon.stub();
callCluster.withArgs('indices.getTemplate').returns(Promise.resolve({ tasky: {} }));
const store = new TaskStore({
callCluster,
getKibanaUuid,
logger: mockLogger(),
index: 'tasky',
maxAttempts: 2,
supportedTypes: ['a', 'b', 'c'],
});
await store.init();
sinon.assert.calledTwice(callCluster); // store.init calls twice: once to check for existing template, once to put the template (if needed)
sinon.assert.calledWithMatch(callCluster, 'indices.putTemplate', {
body: {
index_patterns: ['tasky'],
settings: {
number_of_shards: 1,
auto_expand_replicas: '0-1',
},
},
name: 'tasky',
});
});
示例7: it
it('redirects to the home page if new SAML Response is for the same user.', async () => {
const request = requestFixture({ payload: { SAMLResponse: 'saml-response-xml' } });
const user = { username: 'user', authentication_realm: { name: 'saml1' } };
callWithRequest.withArgs(request, 'shield.authenticate').resolves(user);
callWithInternalUser
.withArgs('shield.samlAuthenticate')
.resolves({ access_token: 'new-valid-token', refresh_token: 'new-valid-refresh-token' });
const deleteAccessTokenStub = callWithInternalUser
.withArgs('shield.deleteAccessToken')
.resolves({ invalidated_tokens: 1 });
const authenticationResult = await provider.authenticate(request, {
accessToken: 'existing-valid-token',
refreshToken: 'existing-valid-refresh-token',
});
sinon.assert.calledWithExactly(callWithInternalUser, 'shield.samlAuthenticate', {
body: { ids: [], content: 'saml-response-xml' },
});
sinon.assert.calledTwice(deleteAccessTokenStub);
sinon.assert.calledWithExactly(deleteAccessTokenStub, 'shield.deleteAccessToken', {
body: { token: 'existing-valid-token' },
});
sinon.assert.calledWithExactly(deleteAccessTokenStub, 'shield.deleteAccessToken', {
body: { refresh_token: 'existing-valid-refresh-token' },
});
expect(authenticationResult.redirected()).toBe(true);
expect(authenticationResult.redirectURL).toBe('/test-base-path/');
});
示例8: test
test('callback is called when a toast is removed', () => {
const { toastNotifications } = setup();
const onChangeSpy = sinon.spy();
toastNotifications.onChange(onChangeSpy);
const toast = toastNotifications.add({});
toastNotifications.remove(toast);
sinon.assert.calledTwice(onChangeSpy);
});