main.js 2.0 KB

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