11cb0ef41Sopenharmony_civar expect = require('expect.js'), 21cb0ef41Sopenharmony_ci qrcode = require('./../lib/main'), 31cb0ef41Sopenharmony_ci sinon = require('sinon'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_cidescribe('in the main module', function() { 61cb0ef41Sopenharmony_ci describe('the generate method', function () { 71cb0ef41Sopenharmony_ci describe('when not providing a callback', function () { 81cb0ef41Sopenharmony_ci beforeEach(function () { 91cb0ef41Sopenharmony_ci sinon.stub(console, 'log'); 101cb0ef41Sopenharmony_ci }); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci afterEach(function () { 131cb0ef41Sopenharmony_ci sinon.sandbox.restore(); 141cb0ef41Sopenharmony_ci console.log.reset(); 151cb0ef41Sopenharmony_ci }); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci it('logs to the console', function () { 181cb0ef41Sopenharmony_ci qrcode.generate('test'); 191cb0ef41Sopenharmony_ci expect(console.log.called).to.be(true); 201cb0ef41Sopenharmony_ci }); 211cb0ef41Sopenharmony_ci }); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci describe('when providing a callback', function () { 241cb0ef41Sopenharmony_ci it('will call the callback', function () { 251cb0ef41Sopenharmony_ci var cb = sinon.spy(); 261cb0ef41Sopenharmony_ci qrcode.generate('test', cb); 271cb0ef41Sopenharmony_ci expect(cb.called).to.be(true); 281cb0ef41Sopenharmony_ci }); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci it('will not call the console.log method', function () { 311cb0ef41Sopenharmony_ci qrcode.generate('test', sinon.spy()); 321cb0ef41Sopenharmony_ci expect(console.log.called).to.be(false); 331cb0ef41Sopenharmony_ci }); 341cb0ef41Sopenharmony_ci }); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci describe('the QR Code', function () { 371cb0ef41Sopenharmony_ci it('should be a string', function (done) { 381cb0ef41Sopenharmony_ci qrcode.generate('test', function(result) { 391cb0ef41Sopenharmony_ci expect(result).to.be.a('string'); 401cb0ef41Sopenharmony_ci done(); 411cb0ef41Sopenharmony_ci }); 421cb0ef41Sopenharmony_ci }); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci it('should not end with a newline', function (done) { 451cb0ef41Sopenharmony_ci qrcode.generate('test', function(result) { 461cb0ef41Sopenharmony_ci expect(result).not.to.match(/\n$/); 471cb0ef41Sopenharmony_ci done(); 481cb0ef41Sopenharmony_ci }); 491cb0ef41Sopenharmony_ci }); 501cb0ef41Sopenharmony_ci }); 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci describe('the error level', function () { 531cb0ef41Sopenharmony_ci it('should default to 1', function() { 541cb0ef41Sopenharmony_ci expect(qrcode.error).to.be(1); 551cb0ef41Sopenharmony_ci }); 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci it('should not allow other levels', function() { 581cb0ef41Sopenharmony_ci qrcode.setErrorLevel = 'something'; 591cb0ef41Sopenharmony_ci expect(qrcode.error).to.be(1); 601cb0ef41Sopenharmony_ci }); 611cb0ef41Sopenharmony_ci }); 621cb0ef41Sopenharmony_ci }); 631cb0ef41Sopenharmony_ci}); 64