Musical keyboard component written in React.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

77 lignes
1.8 KiB

  1. import * as fc from 'fast-check'
  2. import isNaturalKey from './isNaturalKey'
  3. it('should exist', () => {
  4. expect(isNaturalKey).toBeDefined()
  5. })
  6. it('should be a callable', () => {
  7. expect(typeof isNaturalKey).toBe('function')
  8. })
  9. it('should accept 1 parameter', () => {
  10. expect(isNaturalKey).toHaveLength(1)
  11. })
  12. it('should throw TypeError upon passing invalid types', () => {
  13. fc.assert(
  14. fc.property(
  15. fc.anything().filter(anything => typeof anything !== 'number'),
  16. anything => {
  17. expect(() => isNaturalKey(anything as number)).toThrowError(TypeError)
  18. }
  19. )
  20. )
  21. })
  22. it('should throw RangeError upon passing NaN', () => {
  23. expect(() => isNaturalKey(NaN)).toThrowError(RangeError)
  24. })
  25. it('should throw RangeError upon passing negative numbers', () => {
  26. fc.assert(
  27. fc.property(
  28. fc.anything().filter(anything => (
  29. typeof anything! === 'number'
  30. && !isNaN(anything)
  31. && anything < 0
  32. )),
  33. negativeValue => {
  34. expect(() => isNaturalKey(negativeValue as number)).toThrowError(RangeError)
  35. }
  36. )
  37. )
  38. })
  39. describe('upon passing a positive number or zero', () => {
  40. it('should not throw any error', () => {
  41. fc.assert(
  42. fc.property(
  43. fc.anything().filter(anything => (
  44. typeof anything! === 'number'
  45. && !isNaN(anything)
  46. && anything >= 0
  47. )),
  48. value => {
  49. expect(() => isNaturalKey(value as number)).not.toThrow()
  50. }
  51. )
  52. )
  53. })
  54. it('should return a boolean', () => {
  55. fc.assert(
  56. fc.property(
  57. fc.anything().filter(anything => (
  58. typeof anything! === 'number'
  59. && !isNaN(anything)
  60. && anything >= 0
  61. )),
  62. value => {
  63. expect(typeof isNaturalKey(value as number)).toBe('boolean')
  64. }
  65. )
  66. )
  67. })
  68. })