UNPKG

@w11r/use-breakpoint

Version:

React useBreakpoint hook to have different values for a variable based on a breakpoints.

36 lines (32 loc) 1.28 kB
"use strict"; var _useBreakpoint = require("./useBreakpoint"); /** Cheat-sheet micro: [0, 375], mobile: [376, 639], tablet: [640, 1023], small: [1024, 1439], medium: [1440, 1919], large: [1920, 10000] */ var iter = (_ref) => { var [toBe, defaultValue, breakpointValues, iw] = _ref; it("should return ".concat(toBe, " if dv=").concat(defaultValue, " bp=").concat(breakpointValues.map((_ref2) => { var [k, v] = _ref2; return "".concat(k, ":").concat(v); }).join(';'), " and iw=").concat(iw), () => { expect((0, _useBreakpoint.calculateValue)(defaultValue, breakpointValues, iw, 0)).toBe(toBe); }); }; describe('useBreakpoint', () => { // toBe, defaultValue, breakpointValues, iw var testValues = [[300, 100, [['mobile', 300]], 400], [100, 100, [['mobile', 300]], 800], [300, 100, [['mobile+', 300]], 800], [400, 100, [['tablet', 400], ['mobile+', 300]], 800]]; // @ts-ignore testValues.forEach(iter); it("should work with single array value", () => { expect((0, _useBreakpoint.calculateValue)(300, ['mobile+', 500], 400, 0)).toBe(500); }); it("should return 'is{Key}' properties if no props were given", () => { // @ts-ignore expect((0, _useBreakpoint.calculateValue)(undefined, [], 500, 0).isMobile).toBe(true); }); });