UNPKG

@ray-core/runtime

Version:

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

33 lines (32 loc) 1.39 kB
import * as React from 'react'; import TestRenderer from 'react-test-renderer'; import createNativeComponent from '../createNativeComponent'; describe('createNativeComponent', function () { it('create native component', function () { var Card = createNativeComponent('card'); var testRenderer = TestRenderer.create(React.createElement(Card, null)); expect(testRenderer.toJSON()).toMatchSnapshot(); expect(function () { testRenderer.root.findByType('card').props.__ref('foo'); }).not.toThrow(); }); it('rename ref', function () { var Card = createNativeComponent('card'); var card = React.createRef(); var testRenderer = TestRenderer.create(React.createElement(Card, { ref: card })); expect(testRenderer.toJSON()).toMatchSnapshot(); testRenderer.root.findByType('card').props.__ref('foo'); expect(card.current).toBe('foo'); }); it('functional ref', function () { var Card = createNativeComponent('card'); var current = ''; var card = function (e) { current = e; }; var testRenderer = TestRenderer.create(React.createElement(Card, { ref: card })); expect(testRenderer.toJSON()).toMatchSnapshot(); testRenderer.root.findByType('card').props.__ref('foo'); expect(current).toBe('foo'); }); });