diff --git a/packages/inula/scripts/__tests__/ReactivityTest/no-vnode/no-vnode-base.test.js b/packages/inula/scripts/__tests__/ReactivityTest/no-vnode/no-vnode-base.test.js new file mode 100644 index 00000000..947eff0f --- /dev/null +++ b/packages/inula/scripts/__tests__/ReactivityTest/no-vnode/no-vnode-base.test.js @@ -0,0 +1,558 @@ +import Inula, { computed, createRef, reactive, watchReactive } from '../../../../src/index'; +import { template as _$template, insert as _$insert, setAttribute as _$setAttribute } from '../../../../src/no-vnode/dom'; +import { createComponent as _$createComponent, render } from '../../../../src/no-vnode/core'; +import { delegateEvents as _$delegateEvents, addEventListener as _$addEventListener } from '../../../../src/no-vnode/event'; + +import { Show } from '../../../../src/no-vnode/components/Show'; +import { For } from '../../../../src/no-vnode/components/For'; + +describe('测试 no-vnode', () => { + it('简单的使用signal', () => { + /** + * 源码: + * const CountingComponent = () => { + * const [count, setCount] = useSignal(0); + * + * return
Count value is {count()}.
; + * }; + * + * render(() => , container); + */ + + let g_count; + + // 编译后: + const _tmpl$ = /*#__PURE__*/ _$template(`
Count value is .`); + const CountingComponent = () => { + const count = reactive(0); + g_count = count; + + return (() => { + const _el$ = _tmpl$(), + _el$2 = _el$.firstChild, + _el$4 = _el$2.nextSibling, + _el$3 = _el$4.nextSibling; + _$insert(_el$, count, _el$4); + return _el$; + })(); + }; + render(() => _$createComponent(CountingComponent, {}), container); + + _$delegateEvents(['click']); + + expect(container.querySelector('#count').innerHTML).toEqual('Count value is 0.'); + + g_count.set(c => c + 1); + + expect(container.querySelector('#count').innerHTML).toEqual('Count value is 1.'); + }); + + it('return数组,click事件', () => { + /** + * 源码: + * const CountingComponent = () => { + * const [count, setCount] = createSignal(0); + * const add = () => { + * setCount((c) => c + 1); + * } + * return <> + *
Count value is {count()}.
+ *
+ * ; + * }; + */ + + // 编译后: + const _tmpl$ = /*#__PURE__*/ _$template(`
Count value is .`), + _tmpl$2 = /*#__PURE__*/ _$template(`
+ *
; + * }; + * + * render(() => , document.getElementById("app")); + */ + + // 编译后: + const _tmpl$ = /*#__PURE__*/ _$template(`
Count value is .`), + _tmpl$2 = /*#__PURE__*/ _$template(`
+ *
; + * }; + * + * render(() => , document.getElementById("app")); + */ + + // 编译后: + const _tmpl$ = /*#__PURE__*/ _$template(`
Count value is .`), + _tmpl$2 = /*#__PURE__*/ _$template(`
+ *
+ *
; + * }; + * + * render(() => , document.getElementById("app")); + */ + + // 编译后: + const _tmpl$ = /*#__PURE__*/_$template(`
Count value is .`), + _tmpl$2 = /*#__PURE__*/_$template(`
+ *
+ * ); + * + * const Main = () => { + * const [state, setState] = createStore({data: [{id: 1, label: '111', selected: false}, {id: 2, label: '222', selected: false}], num: 2}); + * + * function run() { + * setState('data', buildData(5)); + * } + * + * return ( + *
+ *
+ *
+ *

Horizon-reactive-novnode

+ *
+ *
+ *
+ *
+ *
+ *
+ * + * + *
+ *
+ * ); + * }; + * + * render(() =>
, document.getElementById("app")); + */ + + // 编译后: + const _tmpl$ = /*#__PURE__*/_$template(``), + _tmpl$2 = /*#__PURE__*/_$template(`