test.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. var assert = require('assert')
  2. var mime = require('..')
  3. var lookup = mime.lookup
  4. var extension = mime.extension
  5. var charset = mime.charset
  6. var contentType = mime.contentType
  7. describe('.lookup()', function () {
  8. it('jade', function () {
  9. assert.equal(lookup('jade'), 'text/jade')
  10. assert.equal(lookup('.jade'), 'text/jade')
  11. assert.equal(lookup('file.jade'), 'text/jade')
  12. assert.equal(lookup('folder/file.jade'), 'text/jade')
  13. })
  14. it('should not error on non-string types', function () {
  15. assert.doesNotThrow(function () {
  16. lookup({ noteven: "once" })
  17. lookup(null)
  18. lookup(true)
  19. lookup(Infinity)
  20. })
  21. })
  22. it('should return false for unknown types', function () {
  23. assert.equal(lookup('.jalksdjflakjsdjfasdf'), false)
  24. })
  25. })
  26. describe('.extension()', function () {
  27. it('should not error on non-string types', function () {
  28. assert.doesNotThrow(function () {
  29. extension({ noteven: "once" })
  30. extension(null)
  31. extension(true)
  32. extension(Infinity)
  33. })
  34. })
  35. it('should return false for unknown types', function () {
  36. assert.equal(extension('.jalksdjflakjsdjfasdf'), false)
  37. })
  38. })
  39. describe('.charset()', function () {
  40. it('should not error on non-string types', function () {
  41. assert.doesNotThrow(function () {
  42. charset({ noteven: "once" })
  43. charset(null)
  44. charset(true)
  45. charset(Infinity)
  46. })
  47. })
  48. it('should return false for unknown types', function () {
  49. assert.equal(charset('.jalksdjflakjsdjfasdf'), false)
  50. })
  51. })
  52. describe('.contentType()', function () {
  53. it('html', function () {
  54. assert.equal(contentType('html'), 'text/html; charset=utf-8')
  55. })
  56. it('text/html; charset=ascii', function () {
  57. assert.equal(contentType('text/html; charset=ascii'), 'text/html; charset=ascii')
  58. })
  59. it('json', function () {
  60. assert.equal(contentType('json'), 'application/json; charset=utf-8')
  61. })
  62. it('application/json', function () {
  63. assert.equal(contentType('application/json'), 'application/json; charset=utf-8')
  64. })
  65. it('jade', function () {
  66. assert.equal(contentType('jade'), 'text/jade; charset=utf-8')
  67. })
  68. it('should not error on non-string types', function () {
  69. assert.doesNotThrow(function () {
  70. contentType({ noteven: "once" })
  71. contentType(null)
  72. contentType(true)
  73. contentType(Infinity)
  74. })
  75. })
  76. it('should return false for unknown types', function () {
  77. assert.equal(contentType('.jalksdjflakjsdjfasdf'), false)
  78. })
  79. })