diff --git a/src/index.js b/src/index.js index 36c147e..a51ef35 100644 --- a/src/index.js +++ b/src/index.js @@ -51,10 +51,6 @@ export default function prepass( c.state = {}; } - // options.render was renamed to _render (mangled to __r) - if (options.render) options.render(vnode); - if (options.__r) options.__r(vnode); - let isClassComponent = false; // Necessary for createContext api. Setting this property will pass @@ -78,6 +74,9 @@ export default function prepass( try { const previousSkipEffects = options[_skipEffects]; options[_skipEffects] = true; + // options.render was renamed to _render (mangled to __r) + if (options.render) options.render(vnode); + if (options.__r) options.__r(vnode); const renderResult = Promise.resolve( nodeName.call(vnode.__c, props, cctx) ); @@ -116,6 +115,9 @@ export default function prepass( doRender = () => { try { + // options.render was renamed to _render (mangled to __r) + if (options.render) options.render(vnode); + if (options.__r) options.__r(vnode); return Promise.resolve(c.render(c.props, c.state, c.context)); } catch (e) { if (e && e.then) { diff --git a/src/index.test.js b/src/index.test.js index bfbb898..295f6c8 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -124,6 +124,42 @@ describe("prepass", () => { }); }); + it("should call options.render for function components", async () => { + const render = jest.fn(); + const r = jest.fn(); + options.render = render; + options.__r = r; + const Component = jest.fn(() =>
); + + const promise = prepass(); + + const result = await promise; + expect(result).toEqual(undefined); + + expect(render).toHaveBeenCalledTimes(1); + expect(r).toHaveBeenCalledTimes(1); + }); + + it("should call options.render for class components", async () => { + const render = jest.fn(); + const r = jest.fn(); + options.render = render; + options.__r = r; + + class Outer extends Component { + render() { + return
+ } + } + const outerRenderSpy = jest.spyOn(Outer.prototype, "render"); + + await prepass(); + + expect(outerRenderSpy).toHaveBeenCalled(); + expect(render).toHaveBeenCalledTimes(1); + expect(r).toHaveBeenCalledTimes(1); + }); + describe("vnode traversal", () => { it("should traverse functional components", async () => { const Inner = jest.fn(() =>
);