isTruthy.test.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import isTruthy from '../../src/utils/isTruthy';
  20. describe('isTruthy', () => {
  21. it('evals false-looking strings properly', () => {
  22. expect(isTruthy('f')).toBe(false);
  23. expect(isTruthy('false')).toBe(false);
  24. expect(isTruthy('no')).toBe(false);
  25. expect(isTruthy('n')).toBe(false);
  26. expect(isTruthy('F')).toBe(false);
  27. expect(isTruthy('False')).toBe(false);
  28. expect(isTruthy('NO')).toBe(false);
  29. expect(isTruthy('N')).toBe(false);
  30. });
  31. it('evals true-looking strings properly', () => {
  32. expect(isTruthy('t')).toBe(true);
  33. expect(isTruthy('true')).toBe(true);
  34. expect(isTruthy('yes')).toBe(true);
  35. expect(isTruthy('y')).toBe(true);
  36. expect(isTruthy('Y')).toBe(true);
  37. expect(isTruthy('True')).toBe(true);
  38. expect(isTruthy('Yes')).toBe(true);
  39. expect(isTruthy('YES')).toBe(true);
  40. });
  41. it('evals bools properly', () => {
  42. expect(isTruthy(false)).toBe(false);
  43. expect(isTruthy(true)).toBe(true);
  44. });
  45. it('evals ints properly', () => {
  46. expect(isTruthy(0)).toBe(false);
  47. expect(isTruthy(1)).toBe(true);
  48. });
  49. it('evals constants properly', () => {
  50. expect(isTruthy(null)).toBe(false);
  51. expect(isTruthy(undefined)).toBe(false);
  52. });
  53. it('string auto is false', () => {
  54. expect(isTruthy('false')).toBe(false);
  55. });
  56. });