UNPKG

@findify/react-components

Version:
161 lines (146 loc) 5.37 kB
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } import { mount } from 'enzyme'; import Image from "./index"; import { jsx as _jsx } from "react/jsx-runtime"; var createFetcher = function createFetcher() { var lastSrc; var lastResolve; var lastReject; return { fetch: function fetch(src) { if (!!lastSrc) throw new Error('Reject or resolve last fetch before running new one!'); lastSrc = src; return new Promise(function (resolve, reject) { lastResolve = resolve; lastReject = reject; }); }, resolve: function resolve() { lastResolve(lastSrc); lastSrc = null; }, reject: function reject() { lastReject(lastSrc); lastSrc = null; } }; }; var nextTick = function nextTick() { return new Promise(function (resolve, reject) { return process.nextTick(resolve); }); }; describe('<Image />', function () { var fetcher; beforeEach(function () { fetcher = createFetcher(); }); it('renders correctly for only src image', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { var fetcher, component; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: fetcher = createFetcher(); component = mount( /*#__PURE__*/_jsx(Image, { fetchImage: fetcher.fetch, src: "foo.png" })); expect(component.html()).toMatchSnapshot(); fetcher.resolve(); _context.next = 6; return nextTick(); case 6: expect(component.html()).toMatchSnapshot(); case 7: case "end": return _context.stop(); } } }, _callee); }))); it('renders correctly for only src image respecting aspect ratio', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { var component; return regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: component = mount( /*#__PURE__*/_jsx(Image, { fetchImage: fetcher.fetch, aspectRatio: 0.5, src: "foo.png" })); expect(component.html()).toMatchSnapshot(); fetcher.resolve(); _context2.next = 5; return nextTick(); case 5: expect(component.html()).toMatchSnapshot(); case 6: case "end": return _context2.stop(); } } }, _callee2); }))); it('renders correctly for src and thumbnail', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { var component; return regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: component = mount( /*#__PURE__*/_jsx(Image, { fetchImage: fetcher.fetch, src: "foo.png", thumbnail: 'baz.png' })); expect(component.html()).toMatchSnapshot(); fetcher.resolve(); _context3.next = 5; return nextTick(); case 5: expect(component.html()).toMatchSnapshot(); fetcher.resolve(); _context3.next = 9; return nextTick(); case 9: expect(component.html()).toMatchSnapshot(); case 10: case "end": return _context3.stop(); } } }, _callee3); }))); it('renders correctly for src and thumbnail respecting aspect ratio', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() { var component; return regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: component = mount( /*#__PURE__*/_jsx(Image, { fetchImage: fetcher.fetch, aspectRatio: 0.8, src: "foo.png", thumbnail: 'baz.png' })); expect(component.html()).toMatchSnapshot(); fetcher.resolve(); _context4.next = 5; return nextTick(); case 5: expect(component.html()).toMatchSnapshot(); fetcher.resolve(); _context4.next = 9; return nextTick(); case 9: expect(component.html()).toMatchSnapshot(); case 10: case "end": return _context4.stop(); } } }, _callee4); }))); });