本文整理汇总了TypeScript中simple-mock.mock函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mock函数的具体用法?TypeScript mock怎么用?TypeScript mock使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mock函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("will reject expired incoming messages", function (done) {
const confirmMethod = simple.mock(AMQPSubscriberAdapter.prototype,
"confirmProcessedMessage");
const rejectMethod = simple.mock(AMQPSubscriberAdapter.prototype,
"rejectMessage");
const onMessageMethod = simple.mock();
consumer.on("message", onMessageMethod);
const expiredMessage = merge({}, fixtures.consumer_basic, {
meta: {ttl: 10000},
});
publisher.publish([
fixtures.consumer_basic,
expiredMessage,
fixtures.consumer_basic,
], function (err) {
if (err) return done(err);
setTimeout(function () {
expect(onMessageMethod.callCount).equals(2);
expect(onMessageMethod.calls[0].arg).deep.equals(fixtures.consumer_basic);
expect(onMessageMethod.calls[1].arg).deep.equals(fixtures.consumer_basic);
expect(rejectMethod.callCount).equals(1);
expect(confirmMethod.callCount).equals(2);
expect(rejectMethod.lastCall.k).above(confirmMethod.calls[0].k);
expect(rejectMethod.lastCall.k).below(confirmMethod.calls[1].k);
done();
}, 100);
});
});
示例2: applyBuildMocks
function applyBuildMocks(buildQueue : Array<any>) {
builds_mock.queue = buildQueue;
simple.mock(builds, 'getNextQueued').callFn(builds_mock.getNextQueued);
simple.mock(builds, 'markAsStarted').callFn(builds_mock.markAsStarted);
simple.mock(builds, 'markAsSuccess').callFn(builds_mock.markAsSuccess);
simple.mock(builds, 'markAsFailed').callFn(builds_mock.markAsFailed);
}
示例3: it
it("can wait for acks without any determined number of responses", function(done) {
producer.publish.callbackWith();
const endHandler = simple.mock();
const obj = new Requester({
waitForResponses: 0,
waitForAcksMs: 800,
});
simple.mock(obj, "listenForResponses").returnWith();
simple.mock(obj, "isAwaitingAcks").returnWith(true);
simple.mock(messageFactory, "createRequestMessage").returnWith({
topics: {to: "my:topic", response: "my:topic:response"},
});
obj
.on("end", endHandler)
.publish({});
expect((obj.listenForResponses as any).called).to.equal(true);
expect((obj.listenForResponses as any).lastCall.args[0]).to.equal("my:topic:response");
expect(producer.publish.called).to.equal(true);
expect(endHandler.called).to.equal(false);
done();
});
示例4: it
it("should set serviceDetails dynamically", function (done) {
const fakeInterfaces = {
en0: [{
address: "1.2.3.4",
netmask: "255.255.255.0",
family: "IPv4",
mac: "60:03:08:92:27:88",
internal: false,
}],
};
simple.mock(require("os"), "networkInterfaces").returnWith(fakeInterfaces);
simple.mock(require("os"), "hostname").returnWith("abchost");
serviceDetails = require(serviceDetailsModulePath);
expect(serviceDetails.hostname).equals("abchost");
expect(serviceDetails.ip).equals("1.2.3.4");
expect(serviceDetails.pid).equals(process.pid);
expect(serviceDetails.name).to.be.a("string");
expect(!!serviceDetails.version.match(/\d+\.\d+\.\d+/)).to.be.true;
expect(serviceDetails.instanceId).length(24);
done();
});
示例5: beforeEach
beforeEach(function (done) {
simple.restore();
simple.mock(connection, "publish");
simple.mock(connection, "exchange");
simple.mock(exchange, "declare");
simple.mock(publisher, "publishMessageStr");
done();
});