本文整理匯總了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();
});