Code Monkey home page Code Monkey logo

node-amqp-mock's Introduction

node-amqp-mock

This is a mocking and expectations library for node-amqp inspired by nock.

Usage

On your test, you can setup your mocking object like this:

    var amqp = require('amqp');
    var amqpmock = require('amqp-mock');

    var scope = amqpmock(amqp, {url: 'amqp://guest:guest@localhost:5672'})
        .exchange('topic_animals', {type: 'topic'})
            .publish('quick.orange.rabbit', 'Hello')
            .publish('lazy.brown.fox', 'World')
        .exchange('work', {type: 'fanout'})
            .publish('', 'approve', {ack: true}) // expect to be acknowledged
            .publish('', 'disapprove', {ack: false}) // expect to be not acknowledged
        ;

    var connection = amqp.createConnection({url: 'amqp://guest:guest@localhost:5672'});

    connection.on('ready', function(){
        connection.exchange('topic_animals', {type:'topic'}, function(exchange){
            connection.queue('', function(queue){

                queue.bind(exchange.name, '*.*.rabbit');
                queue.bind(exchange.name, 'lazy.#');

                queue.subscribe({ack: false}, function(message){
                    console.log(message.data);
                });
            });
        });
        connection.exchange('work', {type:'fanout'}, function(exchange){
            connection.queue('', function(queue){

                queue.bind(exchange.name, '');

                queue.subscribe({ack: true}, function(message){
                    console.log(message.data);
                    if (message.data === 'approve')
                        queue.shift();
                });
            });
        });
    });

    setTimeout(function(){
        // This will assert that all specified calls on the scope were performed.
        scope.done();
    }, 10);

Versioning

Since we depend on node-amqp internals and public API, node-amqp-mock version number is aligned with node-amqp version. A build number is added to specify updates.

For example, node-amqp-mock 0.1.2-3 would be the third revision compatible with node-amqp 0.1.2

node-amqp-mock's People

Contributors

rstuven avatar

Watchers

James Cloos avatar Ryan Milbourne avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.