UNPKG

@ray-core/runtime

Version:

Ray 是一个全新的基于 React 的小程序开发框架

163 lines (162 loc) 5.58 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import * as React from 'react'; import './helpers/setupGlobals'; import App from './helpers/App'; import { useAppEvent } from '../hooks'; import createAppConfig from '../createAppConfig'; import { RuntimeOptions } from '@ray-core/framework-shared'; describe('app', function () { beforeAll(function () { RuntimeOptions.apply({ appEvents: [ 'onLaunch', 'onShow', 'onHide', 'onShareAppMessage', 'onPageNotFound', 'onError', 'onUnhandledRejection', 'onThemeChange', ], pageEvents: { 'pages/test/only/onshow': ['onShow'], 'pages/test/index': [ 'onShow', 'onHide', 'onPullDownRefresh', 'onPullIntercept', 'onReachBottom', 'onPageScroll', 'onShareAppMessage', 'onShareTimeline', 'onTitleClick', 'onOptionMenuClick', 'onPopMenuClick', 'onReady', 'onResize', 'onTabItemTap', ], }, }); }); afterAll(function () { RuntimeOptions.reset(); }); it('lifecycle methods', function () { var log = []; var Foo = /** @class */ (function (_super) { __extends(Foo, _super); function Foo() { return _super !== null && _super.apply(this, arguments) || this; } Foo.prototype.onLaunch = function () { log.push('onLaunch'); }; Foo.prototype.onShow = function () { log.push('onShow'); }; Foo.prototype.onHide = function () { log.push('onHide'); }; Foo.prototype.onError = function (error) { log.push(error); log.push('onError'); }; Foo.prototype.onShareAppMessage = function (object) { log.push(object.from); log.push('onShareAppMessage'); }; Foo.prototype.onPageNotFound = function (object) { log.push(object.path); log.push('onPageNotFound'); }; Foo.prototype.onUnhandledRejection = function () { log.push('onUnhandledRejection'); }; Foo.prototype.onThemeChange = function () { log.push('onThemeChange'); }; Foo.prototype.render = function () { return React.createElement(React.Fragment, null, this.props.children); }; return Foo; }(React.Component)); var app = App(createAppConfig(Foo)); app.launch(); app.show(); app.shareAppMessage(); app.pageNotFound(); app.error(); app.unhandledRejection(); app.themeChange(); app.hide(); expect(log).toEqual([ 'onLaunch', 'onShow', 'menu', 'onShareAppMessage', 'path', 'onPageNotFound', 'error', 'onError', 'onUnhandledRejection', 'onThemeChange', 'onHide', ]); }); it('hooks', function () { var log = []; function Foo(props) { useAppEvent('onLaunch', function () { log.push('launch'); }); useAppEvent('onShow', function () { log.push('show'); return function () { log.push('unregister show'); }; }); useAppEvent('onShow', function () { log.push('appEventShow'); }); useAppEvent('onPageNotFound', function () { log.push('pageNotFound'); }); useAppEvent('onShareAppMessage', function () { log.push('shareAppMessage'); return {}; }); useAppEvent('onError', function () { log.push('error'); }); useAppEvent('onHide', function () { log.push('hide'); }); return props.children; } var app = App(createAppConfig(Foo)); app.launch(); app.show(); app.pageNotFound(); app.shareAppMessage(); app.error(); app.unhandledRejection(); app.themeChange(); app.hide(); expect(log).toEqual(['launch', 'show', 'appEventShow', 'pageNotFound', 'shareAppMessage', 'error', 'hide']); }); });