UNPKG

@ray-core/runtime

Version:

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

54 lines (53 loc) 2.22 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 createAppConfig from '../createAppConfig'; describe('createAppConfig', function () { var App = /** @class */ (function (_super) { __extends(App, _super); function App() { return _super !== null && _super.apply(this, arguments) || this; } App.prototype.render = function () { return React.createElement(React.Fragment, null, this.props.children); }; return App; }(React.Component)); it('get App ref', function () { var appConfig = createAppConfig(App); appConfig.onLaunch({}); expect(appConfig._instance.current).toBeInstanceOf(App); }); it('get App ref with HOC', function () { var hoc = function (AppComponent) { return React.forwardRef(function (_, ref) { return React.createElement(AppComponent, { ref: ref }); }); }; var appConfig = createAppConfig(hoc(App)); appConfig.onLaunch({}); expect(appConfig._instance.current).toBeInstanceOf(App); }); it('does not pass ref to FC', function () { var FCApp = function (props) { return props.children; }; var appConfig = createAppConfig(FCApp); appConfig.onLaunch({}); expect(appConfig._instance.current).toBeNull(); }); it('use default App', function () { expect(createAppConfig(undefined)).toBeDefined(); }); });