Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. 'use strict'
  2.  
  3. const _ = require( '../' )
  4. const Code = require('code')
  5. const Lab = require('lab')
  6. const lab = exports.lab = Lab.script()
  7.  
  8. const suite = lab.suite
  9. const it = lab.test
  10. const before = lab.before
  11. const describe = lab.experiment
  12. const after = lab.after
  13. const expect = Code.expect
  14.  
  15. describe('_.typeof mixin', () => {
  16.  
  17. // Values to be checked, the withScrutiny enables scrutiny, and the
  18. // withoutScrutiny... guess. And the item keys determine what they
  19. // should be typed as
  20. const checkVals = {
  21. withScrutiny: {
  22. boolean: [ true, false, 'true', 'false'],
  23. number: [ 1, 2.3, '4', '5.6' ],
  24. string: [ 'foo', '7.8.9' ],
  25. null: [ null, 'null', 'NULL' ],
  26. undefined: [ 'undefined' ]
  27. },
  28. withoutScrutiny: {
  29. boolean: [ true, false ],
  30. number: [ 1, 2.3 ],
  31. string: [ 'foo', '1', '2.3', '4.5.6', 'null', 'undefined' ],
  32. null: [ null ],
  33. regexp: [ /foo/i ],
  34. undefined: [ undefined ]
  35. }
  36. }
  37.  
  38. // Automate the majority of the testing
  39. _.forEach(checkVals, ( types, scrTyp ) => {
  40. _.forEach(types, ( vals, type ) => {
  41. _.forEach( vals, v => {
  42. it(`value ${v} to return ${type} (with scrutiny ${scrTyp === 'withScrutiny' ? 'enabled' : 'disabled'})`, done => {
  43. expect( _.typeof( v, scrTyp === 'withScrutiny' ) === type ).to.equal( true )
  44. done()
  45. })
  46. })
  47. })
  48. })
  49.  
  50. it('[1,2,3] to identify as an array', done => {
  51. expect( _.typeof( [1,2,3] ) === 'array').to.equal( true )
  52. done()
  53. })
  54.  
  55. it('{a:1,b:2} to identify as an object', done => {
  56. expect( _.typeof( {a:1,b:2} ) === 'object').to.equal( true )
  57. done()
  58. })
  59.  
  60. it('parseInt() to identify as a function', done => {
  61. expect( _.typeof( parseInt ) === 'function').to.equal( true )
  62. done()
  63. })
  64.  
  65. it('new Date() to identify as a date', done => {
  66. expect( _.typeof( new Date() ) === 'date').to.equal( true )
  67. done()
  68. })
  69.  
  70. it('foo to identify as a "bar" due to the returnTypes parameter being modified', done => {
  71. expect( _.typeof( 'foo', null, { string: 'bar' } ) === 'bar').to.equal( true )
  72. done()
  73. })
  74.  
  75. it('bar to identify as boolean, due to the flaggedVals parameter being modified and scrutinize enabled', done => {
  76. expect( _.typeof( 'bar', true, null, {boolean: ['bar']} ) === 'boolean').to.equal( true )
  77. done()
  78. })
  79.  
  80. /*
  81. it('Illegal additional true type to throw an error', done => {
  82. expect(() => _.bool( 'foo', {bar: 'baz'} )).to.throw( Error )
  83. done()
  84. })
  85. */
  86. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement