UNPKG

zarm

Version:

基于 React 的移动端UI库

64 lines (62 loc) 2.3 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import React from 'react'; import { fireEvent, render } from '@testing-library/react'; import Affix from '../index'; describe('Affix', function () { it('offsetTop', function () { var wrapper = render( /*#__PURE__*/React.createElement(Affix, { offsetTop: 20 }, /*#__PURE__*/React.createElement("div", null, "Affix Node"))); expect(wrapper.asFragment()).toMatchSnapshot(); }); it('offsetBottom', function () { var wrapper = render( /*#__PURE__*/React.createElement(Affix, { offsetBottom: 20 }, /*#__PURE__*/React.createElement("div", null, "Affix Node"))); expect(wrapper.asFragment()).toMatchSnapshot(); }); it('getAffixed is true test of offsetTop', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var wrapper; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: wrapper = render( /*#__PURE__*/React.createElement(Affix, { offsetTop: 100000 }, /*#__PURE__*/React.createElement("div", null, "Affix Node"))); expect(wrapper.asFragment()).toMatchSnapshot(); case 2: case "end": return _context.stop(); } } }, _callee); }))); it('updatePosition when offsetTop changed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { var onChange; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: onChange = jest.fn(); jest.useFakeTimers(); render( /*#__PURE__*/React.createElement(Affix, { offsetTop: 0, onChange: onChange })); jest.runAllTimers(); fireEvent.scroll(window, { target: { scrollY: -100 } }); expect(onChange).toBeCalled(); case 6: case "end": return _context2.stop(); } } }, _callee2); }))); });