UNPKG

@enact/ui

Version:

A collection of simplified unstyled cross-platform UI components for Enact

80 lines (79 loc) 3.52 kB
"use strict"; var _validators = require("../validators"); describe('validators', function () { describe('warn', function () { test('should throw a console warning', function () { var consoleSpy = jest.spyOn(console, 'warn').mockImplementation(function () {}); (0, _validators.warn)('Warning!'); expect(consoleSpy).toHaveBeenCalled(); }); }); describe('validateRange', function () { test('should throw a console warning when \'value\' is less than \'min\'', function () { var consoleSpy = jest.spyOn(console, 'warn').mockImplementation(function () {}); (0, _validators.validateRange)(10, 11, 20, 'component', 'value', 'min', 'max'); expect(consoleSpy).toHaveBeenCalled(); }); test('should throw a console warning when \'value\' is greater than \'max\'', function () { var consoleSpy = jest.spyOn(console, 'warn').mockImplementation(function () {}); (0, _validators.validateRange)(21, 1, 20, 'component', 'value', 'min', 'max'); expect(consoleSpy).toHaveBeenCalled(); }); test('should throw a console warning when \'min\' is greater than \'max\'', function () { var consoleSpy = jest.spyOn(console, 'warn').mockImplementation(function () {}); (0, _validators.validateRange)(10, 21, 20, 'component', 'value', 'min', 'max'); expect(consoleSpy).toHaveBeenCalled(); }); }); describe('validateStepped', function () { test('should throw a console warning when \'value\' is not evenly divisible by \'step\'', function () { var consoleSpy = jest.spyOn(console, 'warn').mockImplementation(function () {}); (0, _validators.validateStepped)(11, 20, 2, 'component', 'value', 'step'); expect(consoleSpy).toHaveBeenCalled(); }); }); describe('validateRangeOnce', function () { var thingSpy; beforeEach(function () { thingSpy = jest.fn().mockReturnValue('ANY_THING_SPY_VALUE'); }); test('should throw a console warning when \'value\' is lower than \'min\'', function () { var consoleSpy = jest.spyOn(console, 'warn').mockImplementation(function () {}); var validateFn = (0, _validators.validateRangeOnce)(thingSpy, { component: 'ANY_COMPONENT' }); var normalizedValues = validateFn({ value: 1, min: 2, max: 10 }); var expected = 'Warning: ANY_COMPONENT value (1) less than min (2)'; expect(consoleSpy).toHaveBeenCalled(); expect(thingSpy).toHaveBeenCalled(); expect(consoleSpy.mock.calls[0][0]).toBe(expected); expect(normalizedValues).toBe('ANY_THING_SPY_VALUE'); }); }); describe('validateSteppedOnce', function () { var thingSpy; beforeEach(function () { thingSpy = jest.fn().mockReturnValue('ANY_THING_SPY_VALUE'); }); test('should throw a console warning when \'value\' is not evenly divisible by \'step\'', function () { var consoleSpy = jest.spyOn(console, 'warn').mockImplementation(function () {}); var validateFn = (0, _validators.validateSteppedOnce)(thingSpy, { component: 'ANY_COMPONENT' }); var normalizedValues = validateFn({ value: 11, min: 2, step: 2 }); var expected = 'Warning: ANY_COMPONENT value (11) must be evenly divisible by step (2)'; expect(consoleSpy).toHaveBeenCalled(); expect(thingSpy).toHaveBeenCalled(); expect(consoleSpy.mock.calls[0][0]).toBe(expected); expect(normalizedValues).toBe('ANY_THING_SPY_VALUE'); }); }); });