init.tap.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict'
  2. var tap = require('tap')
  3. var test = tap.test
  4. var sinon = require('sinon')
  5. var shimmer = require('../index.js')
  6. test('shimmer initialization', function (t) {
  7. t.plan(4)
  8. t.doesNotThrow(function () { shimmer() })
  9. var mock = sinon.expectation
  10. .create('logger')
  11. .withArgs('no original function undefined to wrap')
  12. .once()
  13. t.doesNotThrow(function () {
  14. shimmer({ logger: mock })
  15. }, "initializer doesn't throw")
  16. t.doesNotThrow(function () {
  17. shimmer.wrap()
  18. }, "invoking the wrap method with no params doesn't throw")
  19. t.doesNotThrow(function () {
  20. mock.verify()
  21. }, 'logger method was called with the expected message')
  22. })
  23. test('shimmer initialized with non-function logger', function (t) {
  24. t.plan(2)
  25. var mock = sinon.expectation
  26. .create('logger')
  27. .withArgs("new logger isn't a function, not replacing")
  28. .once()
  29. shimmer({ logger: mock })
  30. t.doesNotThrow(function () {
  31. shimmer({ logger: { ham: 'chunx' } })
  32. }, "even bad initialization doesn't throw")
  33. t.doesNotThrow(function () {
  34. mock.verify()
  35. }, 'logger initialization failed in the expected way')
  36. })