feature-utils-test.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const FU = require('../feature-utils');
  2. describe('FeatureUtils', () => {
  3. const FEATURE_X_KEY = 'my feature 1';
  4. const FEATURE_Y_KEY = 'my feature 2';
  5. beforeEach(() => {
  6. FU.setFeature(FEATURE_X_KEY, false);
  7. FU.setFeature(FEATURE_Y_KEY, false);
  8. });
  9. describe('Setting of features', () => {
  10. it('should not have any features by default', () => {
  11. expect(FU.featureIsEnabled(FEATURE_X_KEY)).toBeFalsy();
  12. expect(FU.featureIsEnabled(FEATURE_Y_KEY)).toBeFalsy();
  13. });
  14. it('should work with enabling one feature', () => {
  15. let success;
  16. expect(FU.featureIsEnabled(FEATURE_X_KEY)).toBeFalsy();
  17. success = FU.setFeature(FEATURE_X_KEY, true);
  18. expect(success).toBeTruthy();
  19. expect(FU.featureIsEnabled(FEATURE_X_KEY)).toBeTruthy();
  20. expect(FU.featureIsEnabled(FEATURE_Y_KEY)).toBeFalsy();
  21. success = FU.setFeature(FEATURE_X_KEY, false);
  22. expect(success).toBeTruthy();
  23. expect(FU.featureIsEnabled(FEATURE_X_KEY)).toBeFalsy();
  24. });
  25. it('should allow for either feature', () => {
  26. let success;
  27. expect(FU.featureIsEnabledAny(FEATURE_X_KEY, FEATURE_Y_KEY)).toBeFalsy();
  28. success = FU.setFeature(FEATURE_X_KEY, true);
  29. expect(success).toBeTruthy();
  30. expect(FU.featureIsEnabledAny(FEATURE_X_KEY, FEATURE_Y_KEY)).toBeTruthy();
  31. success = FU.setFeature(FEATURE_X_KEY, false);
  32. success = FU.setFeature(FEATURE_Y_KEY, true);
  33. expect(success).toBeTruthy();
  34. expect(FU.featureIsEnabledAny(FEATURE_X_KEY, FEATURE_Y_KEY)).toBeTruthy();
  35. });
  36. });
  37. });