Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
loop-ping / test / loop-ping.js
Size: Mime:
var Assert = require("assert");

describe("loop-ping", function(){
    describe("good options", function(){
        it("should not throw with mock logger", function(done){
            Assert.doesNotThrow(function(){
                var called = false;
                require("../src/index.js")({
                    checkIntervalMs : 1,
                    logger : {
                        info : function(message){
                            if(!called) done();
                            called = true;
                        },
                        warn : function(message){
                            if(!called) done();
                            called = true;
                        }
                    }
                });
            });
        });
        it("should not throw with mock logger having extra interfaces", function(done){
            Assert.doesNotThrow(function(){
                var called = false;
                require("../src/index.js")({
                    checkIntervalMs : 1,
                    logger : {
                        info : function(message){
                            if(!called) done();
                            called = true;
                        },
                        warn : function(message){
                            if(!called) done();
                            called = true;
                        },
                        error : function(message){
                            if(!called) done();
                            called = true;
                        }
                    }
                });
            });
        });
    });
    describe("bad options", function(){
        it("should throw when checkIntervalMs is non integer", function(){
           Assert.throws(function(){
               require("../src/index.js")({checkIntervalMs : "a"});
           });
        });
        it("should throw when checkIntervalMs < 1", function(){
            Assert.throws(function(){
                require("../src/index.js")({checkIntervalMs : 0});
            });
        });
        it("should throw when warnDelayMs is non integer", function(){
            Assert.throws(function(){
                require("../src/index.js")({warnDelayMs : "a"});
            });
        });
        it("should throw when warnDelayMs < 1", function(){
            Assert.throws(function(){
                require("../src/index.js")({warnDelayMs : 0});
            });
        });
        it("should throw when logger info func is not defined", function(){
            Assert.throws(function(){
                require("../src/index.js")({
                    logger : {
                        warn : function(message){

                        }
                    }
                });
            });
        });
        it("should throw when logger warn func is not defined", function(){
            Assert.throws(function(){
                require("../src/index.js")({
                    logger : {
                        info : function(message){

                        }
                    }
                });
            });
        });
    });
});