|
1 | 1 | import { render, shallowRender } from '../src';
|
2 |
| -import { h, Component, createContext, Fragment } from 'preact'; |
| 2 | +import { h, Component, createContext, Fragment, options } from 'preact'; |
3 | 3 | import { useState, useContext, useEffect, useLayoutEffect } from 'preact/hooks';
|
4 | 4 | import chai, { expect } from 'chai';
|
5 | 5 | import { spy, stub, match } from 'sinon';
|
@@ -1049,6 +1049,47 @@ describe('render', () => {
|
1049 | 1049 | });
|
1050 | 1050 | });
|
1051 | 1051 |
|
| 1052 | + it('should invoke options._render and options._diff', () => { |
| 1053 | + const calls = []; |
| 1054 | + // _diff |
| 1055 | + const oldDiff = options.__b; |
| 1056 | + options.__b = (...args) => { |
| 1057 | + calls.push(['_diff', args]); |
| 1058 | + if (oldDiff) oldDiff(...args); |
| 1059 | + }; |
| 1060 | + // _render |
| 1061 | + const oldRender = options.__r; |
| 1062 | + options.__r = (...args) => { |
| 1063 | + calls.push(['_render', args]); |
| 1064 | + if (oldRender) oldRender(...args); |
| 1065 | + }; |
| 1066 | + |
| 1067 | + function Component1({ children }) { |
| 1068 | + return children; |
| 1069 | + } |
| 1070 | + |
| 1071 | + function Component2() { |
| 1072 | + return <div />; |
| 1073 | + } |
| 1074 | + |
| 1075 | + const vnode2 = <Component2>1</Component2>; |
| 1076 | + const vnode1 = <Component1>{vnode2}</Component1>; |
| 1077 | + |
| 1078 | + render(vnode1); |
| 1079 | + |
| 1080 | + expect(calls).to.deep.equal([ |
| 1081 | + ['_diff', [vnode1]], |
| 1082 | + ['_render', [vnode1]], |
| 1083 | + ['_diff', [vnode2]], |
| 1084 | + ['_render', [vnode2]] |
| 1085 | + ]); |
| 1086 | + |
| 1087 | + expect(calls.length).to.equal(4); |
| 1088 | + |
| 1089 | + options.__b = oldDiff; |
| 1090 | + options.__r = oldRender; |
| 1091 | + }); |
| 1092 | + |
1052 | 1093 | it('should render select value on option', () => {
|
1053 | 1094 | let res = render(
|
1054 | 1095 | <select value="B">
|
|
0 commit comments