Skip to content

Is it possible to test exported hook methods of a provider? #899

Closed Answered by Macilias
Macilias asked this question in Q&A
Discussion options

You must be logged in to vote

YEAH, i found the solution, and its quite simple:

import { act, renderHook } from "@testing-library/react-hooks";
import { waitFor } from "@testing-library/react-native";
import React from 'react';
import { NodeType } from './model';
import { OntologyProvider, useOntology } from './OntologyProvider';

describe("Nodes", () => {

  it("node creation", async () => {
    const wrapper = ({ children }) => <OntologyProvider testing={true}>{children}</OntologyProvider>
    const { result } = renderHook(() => useOntology(true), { wrapper });
    await waitFor(() => result.current.ontologyIsInitialized);
    await act(async () => {
      result.current.createNode(NodeType.Complex, 'Peter Pan');
  …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@Macilias
Comment options

@Macilias
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by mdjastrzebski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants