UNPKG

luy

Version:

所谓类```React```框架就是**和React用法一模一样**的框架。其实当初制造这个框架的目的是为了能更好的学习React内部结构,了解其原理而制作的玩具。但是随着框架的渐渐成长,代码越来越多,我还是决定将其发展下去. ![](https://github.com/215566435/Luy/blob/master/luy%20icon2.jpg?raw=true)

65 lines (50 loc) 1.61 kB
import React from "../app/src/Luy"; import getTestDocument from "./getTestDocument"; import ReactTestUtils from "../lib/ReactTestUtils"; import ReactShallowRenderer from "../lib/ReactShallowRenderer"; //https://github.com/facebook/react/blob/master/src/isomorphic/children/__tests__/ReactChildren-test.js var ReactDOM = window.ReactDOM || React; describe("ref机制清理", function () { //context穿透更新 it("ref得到清理", () => { var parentInstance = null; var number = 0 class Parent extends React.Component { state = { flag: false }; render() { const child = (<div ref='fuck'> <Child /> <Child /> <Child /> <Child /> <Child /> {this.props.children} </div>) return ( <div>{this.state.flag ? child : null}</div> ) } } class Child extends React.Component { componentWillUnmount() { number++ } render() { childInstance = this; return <span>Child</span>; } } parentInstance = ReactTestUtils.renderIntoDocument( <Parent> <Child /> </Parent> ); parentInstance.setState({ flag: false }) var bool = parentInstance.refs.fuck ? true : false; expect(bool).toBe(false); }); })