MCPcopy
hub / github.com/mobxjs/mobx / testComponent

Function testComponent

packages/mobx-react/__tests__/disposeOnUnmount.test.tsx:13–31  ·  view source on GitHub ↗
(C: ClassC, afterMount?: Function, afterUnmount?: Function)

Source from the content-addressed store, hash-verified

11}
12
13function testComponent(C: ClassC, afterMount?: Function, afterUnmount?: Function) {
14 const ref = React.createRef<ClassC>()
15 const { unmount } = render(<C ref={ref} />)
16
17 let cref = ref.current
18 expect(cref?.methodA).not.toHaveBeenCalled()
19 expect(cref?.methodB).not.toHaveBeenCalled()
20 if (afterMount) {
21 afterMount(cref)
22 }
23
24 unmount()
25
26 expect(cref?.methodA).toHaveBeenCalledTimes(1)
27 expect(cref?.methodB).toHaveBeenCalledTimes(1)
28 if (afterUnmount) {
29 afterUnmount(cref)
30 }
31}
32
33describe("without observer", () => {
34 test("class without componentWillUnmount", async () => {

Callers 1

Calls 1

expectFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…