1var expect = require('expect.js'), 2 qrcode = require('./../lib/main'), 3 sinon = require('sinon'); 4 5describe('in the main module', function() { 6 describe('the generate method', function () { 7 describe('when not providing a callback', function () { 8 beforeEach(function () { 9 sinon.stub(console, 'log'); 10 }); 11 12 afterEach(function () { 13 sinon.sandbox.restore(); 14 console.log.reset(); 15 }); 16 17 it('logs to the console', function () { 18 qrcode.generate('test'); 19 expect(console.log.called).to.be(true); 20 }); 21 }); 22 23 describe('when providing a callback', function () { 24 it('will call the callback', function () { 25 var cb = sinon.spy(); 26 qrcode.generate('test', cb); 27 expect(cb.called).to.be(true); 28 }); 29 30 it('will not call the console.log method', function () { 31 qrcode.generate('test', sinon.spy()); 32 expect(console.log.called).to.be(false); 33 }); 34 }); 35 36 describe('the QR Code', function () { 37 it('should be a string', function (done) { 38 qrcode.generate('test', function(result) { 39 expect(result).to.be.a('string'); 40 done(); 41 }); 42 }); 43 44 it('should not end with a newline', function (done) { 45 qrcode.generate('test', function(result) { 46 expect(result).not.to.match(/\n$/); 47 done(); 48 }); 49 }); 50 }); 51 52 describe('the error level', function () { 53 it('should default to 1', function() { 54 expect(qrcode.error).to.be(1); 55 }); 56 57 it('should not allow other levels', function() { 58 qrcode.setErrorLevel = 'something'; 59 expect(qrcode.error).to.be(1); 60 }); 61 }); 62 }); 63}); 64