Match-id-251f1b0696b6f7418dcac1d6d9b03e3c85f553f9

This commit is contained in:
* 2022-04-24 10:55:50 +08:00 committed by *
parent 2bff70f3d7
commit 70f4751981
15 changed files with 54 additions and 54 deletions

View File

@ -2,7 +2,7 @@ import * as Horizon from '@cloudsop/horizon/index.ts';
import { getLogUtils } from '../jest/testUtils'; import { getLogUtils } from '../jest/testUtils';
describe('Context Test', () => { describe('Context Test', () => {
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
it('Provider及其内部consumer组件都不受制于shouldComponentUpdate函数或者Horizon.memo()', () => { it('Provider及其内部consumer组件都不受制于shouldComponentUpdate函数或者Horizon.memo()', () => {
const LanguageTypes = { const LanguageTypes = {
JAVA: 'Java', JAVA: 'Java',

View File

@ -12,7 +12,7 @@ describe('useEffect Hook Test', () => {
act, act,
} = Horizon; } = Horizon;
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
it('简单使用useEffect', () => { it('简单使用useEffect', () => {
const App = () => { const App = () => {
const [num, setNum] = useState(0); const [num, setNum] = useState(0);

View File

@ -10,7 +10,7 @@ describe('useImperativeHandle Hook Test', () => {
act, act,
} = Horizon; } = Horizon;
const { unmountComponentAtNode } = Horizon; const { unmountComponentAtNode } = Horizon;
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
it('测试useImperativeHandle', () => { it('测试useImperativeHandle', () => {
let App = (props, ref) => { let App = (props, ref) => {

View File

@ -9,7 +9,7 @@ describe('useLayoutEffect Hook Test', () => {
useLayoutEffect, useLayoutEffect,
act, act,
} = Horizon; } = Horizon;
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
it('简单使用useLayoutEffect', () => { it('简单使用useLayoutEffect', () => {
const App = () => { const App = () => {
const [num, setNum] = useState(0); const [num, setNum] = useState(0);

View File

@ -4,8 +4,8 @@ import { Text } from '../../jest/commonComponents';
describe('useMemo Hook Test', () => { describe('useMemo Hook Test', () => {
const { useMemo, useState } = Horizon; const { useMemo, useState } = Horizon;
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
it('测试useMemo', () => { it('测试useMemo', () => {
let setMemo; let setMemo;
const App = () => { const App = () => {

View File

@ -4,8 +4,8 @@ import { Text } from '../../jest/commonComponents';
describe('useRef Hook Test', () => { describe('useRef Hook Test', () => {
const { useState, useRef } = Horizon; const { useState, useRef } = Horizon;
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
it('测试useRef', () => { it('测试useRef', () => {
const App = () => { const App = () => {
const [num, setNum] = useState(1); const [num, setNum] = useState(1);

View File

@ -10,7 +10,7 @@ describe('useState Hook Test', () => {
memo, memo,
act, act,
} = Horizon; } = Horizon;
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
it('简单使用useState', () => { it('简单使用useState', () => {
const App = () => { const App = () => {

View File

@ -2,7 +2,7 @@ import * as Horizon from '@cloudsop/horizon/index.ts';
import { getLogUtils } from '../jest/testUtils'; import { getLogUtils } from '../jest/testUtils';
describe('LifeCycle Test', () => { describe('LifeCycle Test', () => {
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
describe('LifeCycle function', () => { describe('LifeCycle function', () => {
it('不能在componentWillMount里setState', () => { it('不能在componentWillMount里setState', () => {
class App extends Horizon.Component { class App extends Horizon.Component {
@ -195,7 +195,7 @@ describe('LifeCycle Test', () => {
return nextState.num !== this.state.num; return nextState.num !== this.state.num;
} }
componentDidUpdate(){ componentDidUpdate() {
LogUtils.log('componentDidUpdate'); LogUtils.log('componentDidUpdate');
} }
@ -275,7 +275,7 @@ describe('LifeCycle Test', () => {
expect(container.querySelector('p').innerHTML).toBe('2'); expect(container.querySelector('p').innerHTML).toBe('2');
}); });
it('无论什么原因触发了渲染,只要有渲染就会触发getDerivedStateFromProps',() => { it('无论什么原因触发了渲染,只要有渲染就会触发getDerivedStateFromProps', () => {
class App extends Horizon.Component { class App extends Horizon.Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -306,28 +306,28 @@ describe('LifeCycle Test', () => {
}); });
it('生命周期执行顺序', () => { it('生命周期执行顺序', () => {
class InnerApp extends Horizon.Component { class ChildApp extends Horizon.Component {
UNSAFE_componentWillMount() { UNSAFE_componentWillMount() {
LogUtils.log('Inner componentWillMount'); LogUtils.log('Child componentWillMount');
} }
componentDidMount() { componentDidMount() {
LogUtils.log('Inner componentDidMount'); LogUtils.log('Child componentDidMount');
} }
UNSAFE_componentWillReceiveProps() { UNSAFE_componentWillReceiveProps() {
LogUtils.log('Inner componentWillReceiveProps'); LogUtils.log('Child componentWillReceiveProps');
} }
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
LogUtils.log('Inner shouldComponentUpdates'); LogUtils.log('Child shouldComponentUpdates');
return this.props.number !== nextProps.number; return this.props.number !== nextProps.number;
} }
UNSAFE_componentWillUpdate() { UNSAFE_componentWillUpdate() {
LogUtils.log('Inner componentWillUpdate'); LogUtils.log('Child componentWillUpdate');
} }
componentDidUpdate() { componentDidUpdate() {
LogUtils.log('Inner componentDidUpdate'); LogUtils.log('Child componentDidUpdate');
} }
componentWillUnmount() { componentWillUnmount() {
LogUtils.log('Inner componentWillUnmount'); LogUtils.log('Child componentWillUnmount');
} }
render() { render() {
@ -360,7 +360,7 @@ describe('LifeCycle Test', () => {
} }
render() { render() {
return <InnerApp number={this.props.num} />; return <ChildApp number={this.props.num} />;
} }
} }
@ -368,8 +368,8 @@ describe('LifeCycle Test', () => {
expect(container.textContent).toBe('1'); expect(container.textContent).toBe('1');
expect(LogUtils.getAndClear()).toEqual([ expect(LogUtils.getAndClear()).toEqual([
'componentWillMount', 'componentWillMount',
'Inner componentWillMount', 'Child componentWillMount',
'Inner componentDidMount', 'Child componentDidMount',
'componentDidMount' 'componentDidMount'
]); ]);
Horizon.render(<App num={2} />, container); Horizon.render(<App num={2} />, container);
@ -378,40 +378,40 @@ describe('LifeCycle Test', () => {
'componentWillReceiveProps', 'componentWillReceiveProps',
'shouldComponentUpdates', 'shouldComponentUpdates',
'componentWillUpdate', 'componentWillUpdate',
'Inner componentWillReceiveProps', 'Child componentWillReceiveProps',
'Inner shouldComponentUpdates', 'Child shouldComponentUpdates',
'Inner componentWillUpdate', 'Child componentWillUpdate',
'Inner componentDidUpdate', 'Child componentDidUpdate',
'componentDidUpdate' 'componentDidUpdate'
]); ]);
Horizon.unmountComponentAtNode(container); Horizon.unmountComponentAtNode(container);
expect(container.textContent).toBe(''); expect(container.textContent).toBe('');
expect(LogUtils.getAndClear()).toEqual([ expect(LogUtils.getAndClear()).toEqual([
'componentWillUnmount', 'componentWillUnmount',
'Inner componentWillUnmount' 'Child componentWillUnmount'
]); ]);
}); });
it('新生命周期执行顺序', () => { it('新生命周期执行顺序', () => {
class InnerApp extends Horizon.Component { class ChildApp extends Horizon.Component {
static getDerivedStateFromProps(props, state) { static getDerivedStateFromProps(props, state) {
LogUtils.log('Inner getDerivedStateFromProps'); LogUtils.log('Child getDerivedStateFromProps');
} }
componentDidMount() { componentDidMount() {
LogUtils.log('Inner componentDidMount'); LogUtils.log('Child componentDidMount');
} }
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
LogUtils.log('Inner shouldComponentUpdates'); LogUtils.log('Child shouldComponentUpdates');
return this.props.number !== nextProps.number; return this.props.number !== nextProps.number;
} }
componentDidUpdate() { componentDidUpdate() {
LogUtils.log('Inner componentDidUpdate'); LogUtils.log('Child componentDidUpdate');
} }
getSnapshotBeforeUpdate() { getSnapshotBeforeUpdate() {
LogUtils.log('Inner getSnapshotBeforeUpdate'); LogUtils.log('Child getSnapshotBeforeUpdate');
} }
componentWillUnmount() { componentWillUnmount() {
LogUtils.log('Inner componentWillUnmount'); LogUtils.log('Child componentWillUnmount');
} }
render() { render() {
@ -441,7 +441,7 @@ describe('LifeCycle Test', () => {
} }
render() { render() {
return <InnerApp number={this.props.num} />; return <ChildApp number={this.props.num} />;
} }
} }
@ -449,8 +449,8 @@ describe('LifeCycle Test', () => {
expect(container.textContent).toBe('1'); expect(container.textContent).toBe('1');
expect(LogUtils.getAndClear()).toEqual([ expect(LogUtils.getAndClear()).toEqual([
'getDerivedStateFromProps', 'getDerivedStateFromProps',
'Inner getDerivedStateFromProps', 'Child getDerivedStateFromProps',
'Inner componentDidMount', 'Child componentDidMount',
'componentDidMount' 'componentDidMount'
]); ]);
Horizon.render(<App num={2} />, container); Horizon.render(<App num={2} />, container);
@ -458,18 +458,18 @@ describe('LifeCycle Test', () => {
expect(LogUtils.getAndClear()).toEqual([ expect(LogUtils.getAndClear()).toEqual([
'getDerivedStateFromProps', 'getDerivedStateFromProps',
'shouldComponentUpdates', 'shouldComponentUpdates',
'Inner getDerivedStateFromProps', 'Child getDerivedStateFromProps',
'Inner shouldComponentUpdates', 'Child shouldComponentUpdates',
'Inner getSnapshotBeforeUpdate', 'Child getSnapshotBeforeUpdate',
'getSnapshotBeforeUpdate', 'getSnapshotBeforeUpdate',
'Inner componentDidUpdate', 'Child componentDidUpdate',
'componentDidUpdate' 'componentDidUpdate'
]); ]);
Horizon.unmountComponentAtNode(container); Horizon.unmountComponentAtNode(container);
expect(container.textContent).toBe(''); expect(container.textContent).toBe('');
expect(LogUtils.getAndClear()).toEqual([ expect(LogUtils.getAndClear()).toEqual([
'componentWillUnmount', 'componentWillUnmount',
'Inner componentWillUnmount' 'Child componentWillUnmount'
]); ]);
}); });
}); });

View File

@ -4,7 +4,7 @@ import { getLogUtils } from '../jest/testUtils';
describe('Dom Input', () => { describe('Dom Input', () => {
const { act } = Horizon; const { act } = Horizon;
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
describe('type checkbox', () => { describe('type checkbox', () => {
it('没有设置checked属性时控制台不会报错', () => { it('没有设置checked属性时控制台不会报错', () => {

View File

@ -128,14 +128,14 @@ describe('Dom Textarea', () => {
// 非受控切换为受控 // 非受控切换为受控
let realNode = Horizon.render(<textarea defaultValue='text' />, container); let realNode = Horizon.render(<textarea defaultValue='text' />, container);
expect(realNode.value).toBe('text'); expect(realNode.value).toBe('text');
Horizon.render(<textarea value='newtext' onChange={() => {}} />, container); Horizon.render(<textarea value='newtext' onChange={() => { }} />, container);
expect(realNode.value).toBe('newtext'); expect(realNode.value).toBe('newtext');
Horizon.unmountComponentAtNode(container); Horizon.unmountComponentAtNode(container);
// 受控切换为非受控 // 受控切换为非受控
realNode = Horizon.render(<textarea value='text' onChange={() => {}} />, container); realNode = Horizon.render(<textarea value='text' onChange={() => { }} />, container);
expect(realNode.value).toBe('text'); expect(realNode.value).toBe('text');
Horizon.render(<textarea defaultValue='newtext' onChange={() => {}} />, container); Horizon.render(<textarea defaultValue='newtext' onChange={() => { }} />, container);
expect(realNode.value).toBe('text'); expect(realNode.value).toBe('text');
}); });

View File

@ -2,7 +2,7 @@ import * as Horizon from '@cloudsop/horizon/index.ts';
import * as TestUtils from '../jest/testUtils'; import * as TestUtils from '../jest/testUtils';
describe('事件', () => { describe('事件', () => {
const LogUtils =TestUtils.getLogUtils(); const LogUtils = TestUtils.getLogUtils();
it('根节点挂载全量事件', () => { it('根节点挂载全量事件', () => {
const App = () => { const App = () => {
return <div />; return <div />;

View File

@ -2,8 +2,8 @@ import * as Horizon from '@cloudsop/horizon/index.ts';
import { getLogUtils } from '../jest/testUtils'; import { getLogUtils } from '../jest/testUtils';
describe('合成焦点事件', () => { describe('合成焦点事件', () => {
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
it('onFocus', () => { it('onFocus', () => {
const realNode = Horizon.render( const realNode = Horizon.render(
<input <input

View File

@ -2,7 +2,7 @@ import * as Horizon from '@cloudsop/horizon/index.ts';
import { getLogUtils } from '../jest/testUtils'; import { getLogUtils } from '../jest/testUtils';
describe('Keyboard Event', () => { describe('Keyboard Event', () => {
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
it('keydown,keypress,keyup的keycode,charcode', () => { it('keydown,keypress,keyup的keycode,charcode', () => {
const node = Horizon.render( const node = Horizon.render(

View File

@ -2,7 +2,7 @@ import * as Horizon from '@cloudsop/horizon/index.ts';
import { getLogUtils } from '../jest/testUtils'; import { getLogUtils } from '../jest/testUtils';
describe('合成滚轮事件', () => { describe('合成滚轮事件', () => {
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
it('onWheel', () => { it('onWheel', () => {
const realNode = Horizon.render( const realNode = Horizon.render(
@ -36,7 +36,7 @@ describe('合成滚轮事件', () => {
LogUtils.log(e.type + ' handle'); LogUtils.log(e.type + ' handle');
}; };
const realNode = Horizon.render( const realNode = Horizon.render(
<div onWheel={eventHandler}/>, <div onWheel={eventHandler} />,
container container
); );

View File

@ -3,7 +3,7 @@ import { getLogUtils } from './testUtils';
//import failOnConsole from 'jest-fail-on-console'; //import failOnConsole from 'jest-fail-on-console';
//failOnConsole(); //failOnConsole();
const LogUtils =getLogUtils(); const LogUtils = getLogUtils();
global.isDev = process.env.NODE_ENV === 'development'; global.isDev = process.env.NODE_ENV === 'development';
global.container = null; global.container = null;
global.beforeEach(() => { global.beforeEach(() => {