本文整理匯總了TypeScript中Sinon.match函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript match函數的具體用法?TypeScript match怎麽用?TypeScript match使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了match函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should generate a valid resource with a random 4-digit ID', () => {
mockSerializer.toJSON.returns({$class: 'com.org'});
mockSerializer.fromJSON.returns(mockResource);
mockResource.validate = sandbox.stub();
component['resourceDeclaration'] = mockClassDeclaration;
// should start clean
should.not.exist(component['definitionError']);
// run method
component['generateResource']();
// should not result in definitionError
should.not.exist(component['definitionError']);
// resourceDefinition should be set as per serializer.toJSON output
component['resourceDefinition'].should.equal('{\n "$class": "com.org"\n}');
// We use the following internal calls
mockFactory.newResource.should.be.calledWith(undefined,
'class.declaration',
sinon.match(/[0-9]{4}/),
{
generate: 'empty',
includeOptionalFields: false,
disableValidation: true,
allowEmptyId: true
});
component.onDefinitionChanged.should.be.calledOn;
});
示例2: it
it('does not redirect AJAX requests if token refresh fails with 400 error', async () => {
const request = requestFixture({ headers: { 'kbn-xsrf': 'xsrf' }, path: '/some-path' });
callWithRequest
.withArgs(sinon.match({ headers: { authorization: 'Bearer foo' } }), 'shield.authenticate')
.rejects({ statusCode: 401 });
const authenticationError = new errors.BadRequest('failed to refresh token');
callWithInternalUser
.withArgs('shield.getAccessToken', {
body: { grant_type: 'refresh_token', refresh_token: 'bar' },
})
.rejects(authenticationError);
const accessToken = 'foo';
const refreshToken = 'bar';
const authenticationResult = await provider.authenticate(request, {
accessToken,
refreshToken,
});
sinon.assert.calledOnce(callWithRequest);
sinon.assert.calledOnce(callWithInternalUser);
expect(request.headers).not.toHaveProperty('authorization');
expect(authenticationResult.failed()).toBe(true);
expect(authenticationResult.error).toBe(authenticationError);
expect(authenticationResult.user).toBeUndefined();
expect(authenticationResult.state).toBeUndefined();
});
示例3: it
it('fails for AJAX requests with user friendly message if refresh token is expired.', async () => {
const request = requestFixture({ headers: { 'kbn-xsrf': 'xsrf' } });
callWithRequest
.withArgs(
sinon.match({ headers: { authorization: 'Bearer expired-token' } }),
'shield.authenticate'
)
.rejects({ statusCode: 401 });
callWithInternalUser
.withArgs('shield.getAccessToken', {
body: { grant_type: 'refresh_token', refresh_token: 'expired-refresh-token' },
})
.rejects({ statusCode: 400 });
const authenticationResult = await provider.authenticate(request, {
accessToken: 'expired-token',
refreshToken: 'expired-refresh-token',
});
expect(request.headers).not.toHaveProperty('authorization');
expect(authenticationResult.failed()).toBe(true);
expect(authenticationResult.error).toEqual(
Boom.badRequest('Both elasticsearch access and refresh tokens are expired.')
);
});
示例4: it
it("should return an expanded entity set, sending exactly one body", done => {
const parser = new GetRequestParser();
stub(parser, "parse")
.withArgs({ relativeUrl: "/Posts?$expand=Children", body: "" })
.returns({
entitySetName: "Posts",
type: GetRequestType.Collection,
filterExpression: null,
expandTree: { Children: {} },
});
const repository = new Repository<IFilterVisitor>();
stub(repository, "getEntities")
.withArgs(match(type => type.getName() === "Post"), { Children: {} }, null, match.any)
.callsArgWith(3, Result.success([ { Id: "2" } ]));
const responseSender = new GetResponseSenderStub();
stub(responseSender, "arrayResult", entities => {
assert.deepEqual(entities, [ { Id: "2" } ]);
done();
});
const schema = new Schema();
const getHandler = new GetHandler<IFilterVisitor>(schema, parser, repository, responseSender);
getHandler.query({ relativeUrl: "/Posts?$expand=Children", body: "" }, null as any);
});
示例5: it
it('redirects to `overwritten_session` if new SAML Response is for another realm.', async () => {
const request = requestFixture({ payload: { SAMLResponse: 'saml-response-xml' } });
const existingUser = { username: 'user', authentication_realm: { name: 'saml1' } };
callWithRequest
.withArgs(
sinon.match({ headers: { authorization: 'Bearer existing-valid-token' } }),
'shield.authenticate'
)
.resolves(existingUser);
const newUser = { username: 'user', authentication_realm: { name: 'saml2' } };
callWithRequest
.withArgs(
sinon.match({ headers: { authorization: 'Bearer new-valid-token' } }),
'shield.authenticate'
)
.resolves(newUser);
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/overwritten_session');
});
示例6: it
it(`should push the ${report.description.toLowerCase()} report view`, (): void => {
settingsController[`view${report.description}Report` as ReportHandler]();
appController.pushView.should.have.been.calledWith("report", sinon.match({
reportName: report.viewArgs.reportName,
dataSource: sinon.match.func,
args: report.viewArgs.args
}));
});
示例7: it
it('add', function () {
const s = new SpySubscriber();
const set = new Set();
sut = new SetObserver(LF.none, new Lifecycle(), set);
sut.subscribe(s);
set.add(1);
expect(s.handleChange).to.have.been.calledWith('add', match(x => x[0] === 1));
});