🚀 Launch Week Day 5:Introducing Immutable Scans.Learn More →
Socket
Book a DemoInstallSign in
Socket

@saasquatch/universal-hooks-testing-library

Package Overview
Dependencies
Maintainers
11
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@saasquatch/universal-hooks-testing-library

A testing library for universal-hooks

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
11
Created
Source

Universal Hooks Testing Library

This library provides an interface to test hooks written with Universal Hooks. You simply plug an implementation in and continue testing as usual. The API is based off of React Hooks Testing Library.

Usage

First, you plug in an implementation. Here's an example with React:

import * as React from "react";
import * as ReactTestLib from "@testing-library/react-hooks";

setImplementation(React);
setTestImplementation(ReactTestLib);

Or with haunted:

import * as haunted from "haunted";
import * as hauntedTestingLib from "@saasquatch/haunted-hooks-testing-library";

setImplementation(haunted);
setTestImplementation(hauntedTestingLib);

Then, use it like usual.

import { useState } from "@saasquatch/universal-hooks";
import { act, renderHook, setTestImplementation } from "@saasquatch/universal-hooks-testing-library";

test("example", () => {
  function useHook() {
    const [counter, setCounter] = useState(0);
    const inc = setCounter((c) => c + 1);
    return { counter, inc };
  }

  let result;
  act(() => {
    ({ result } = renderHook(useHook));
  });
  expect(result.current.counter).toBe(0);

  act(() => {
    result.current.inc();
  });
  expect(result.current.counter).toBe(1);
});

FAQs

Package last updated on 20 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts