本文整理汇总了TypeScript中Sinon.assert.calledWithMatch方法的典型用法代码示例。如果您正苦于以下问题:TypeScript assert.calledWithMatch方法的具体用法?TypeScript assert.calledWithMatch怎么用?TypeScript assert.calledWithMatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sinon.assert
的用法示例。
在下文中一共展示了assert.calledWithMatch方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: done
sniffer.on('end', () => {
sinon.assert.callCount(spy, 3);
sinon.assert.calledWithMatch(spy, 'lorem-ipsum.txt.gz', match1);
sinon.assert.calledWithMatch(spy, 'lorem-ipsum.txt.gz', match2);
sinon.assert.calledWithMatch(spy, 'lorem-ipsum.txt.gz', match3);
done();
});
示例2: test
test('logs, but does not crash if the work function fails', async () => {
let count = 0;
const logger = mockLogger();
const doneWorking = resolvable();
const poller = new TaskPoller({
store,
logger,
pollInterval: 1,
work: async () => {
++count;
if (count === 1) {
throw new Error('Dang it!');
}
if (count > 1) {
poller.stop();
doneWorking.resolve();
}
},
});
poller.start();
await doneWorking;
expect(count).toEqual(2);
sinon.assert.calledWithMatch(logger.error, /Dang it/i);
});
示例3: 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',
});
});
示例4: it
it("check main flow", () => {
const application = new App.Application();
const app = Express();
const handler: any = {handler: "authenticate"};
const stubAppGet = Sinon.stub(app, "get");
const stubPassportAuthenticate = Sinon.stub(Passport, "authenticate").returns(handler as Express.Handler);
application.initPassportCallback(app);
stubAppGet.restore();
stubPassportAuthenticate.restore();
Sinon.assert.calledOnce(stubPassportAuthenticate);
stubPassportAuthenticate.args[0].length.should.be.equals(2);
stubPassportAuthenticate.args[0][0].should.be.equals("google");
stubPassportAuthenticate.args[0][1].should.be.deep.equals({
failureRedirect: "/login",
session: false,
});
Sinon.assert.calledOnce(stubAppGet);
stubAppGet.calledWith("/auth/callback", handler).should.be.true;
stubAppGet.args[0].length.should.be.equals(3);
const callback: (req, res) => any = stubAppGet.args[0][2];
const stubAppPassportCallback = Sinon.stub(application, "passportCallback");
const req = {request: "Request"};
const res = {response: "Response"};
callback(req, res);
Sinon.assert.calledOnce(stubAppPassportCallback);
Sinon.assert.calledWithMatch(stubAppPassportCallback, req, res);
});
示例5: it
it("should call executor arguments with three functions", () => {
const
spy = sinon.spy(),
instance = new promizr.ProgressPromise(spy);
sinon.assert.calledOnce(spy);
sinon.assert.calledWithMatch(spy, sinon.match.func, sinon.match.func, sinon.match.func);
});
示例6: it
it('calls handle function with all parameters', () => {
const handleResult = spy();
stub(funcs, 'foo').returns('abc');
handler.recv('[1,"abc"]', funcs, special, handleResult);
assert.calledWithMatch(handleResult, 1, 'foo', funcs.foo, funcs, ['abc']);
});
示例7: test
test('it returns normally with no tasks when the index does not exist.', async () => {
const callCluster = sinon.spy(async () => ({ hits: { hits: [] } }));
const store = new TaskStore({
callCluster,
supportedTypes: ['a', 'b', 'c'],
index: 'tasky',
maxAttempts: 2,
});
const result = await store.fetchAvailableTasks();
sinon.assert.calledOnce(callCluster);
sinon.assert.calledWithMatch(callCluster, 'search', { ignoreUnavailable: true });
expect(result.length).toBe(0);
});
示例8: test
test('warns if cancel is called on a non-cancellable task', async () => {
const { runner, logger } = testOpts({
definitions: {
testType: {
createTaskRunner: () => ({
run: async () => undefined,
}),
},
},
});
const promise = runner.run();
await runner.cancel();
await promise;
sinon.assert.calledWithMatch(logger.warning, /not cancellable/);
});