New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@luispablo/test-helpers

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@luispablo/test-helpers

Some small and simple helpers for my unit tests

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
6
200%
Maintainers
1
Weekly downloads
 
Created
Source

test-helpers

Some small and simple helpers for my unit tests

Content

DispatchMock

How to use

import { DispatchMock } from "@luispablo/test-helpers";

...

const expectedActions = ["set item", "remove item"]; // The redux actions you want dispatched
const dispatch = DispatchMock(assert, expectedActions, true);
// the first param is the tape assert Object
// the last param is optional, if set to true makes an assert.comment with the actions dispatched

FetcherMock

This component is a function that works as the new fetch API function, so when your code calls it as fetcher("url") it will return a promise that resolves or reject, based on the params you provide. So, first do

import { FetcherMock } from "@luispablo/test-helpers";

And then, for an HTTP 200 response with a JSON body do

const fetcher = FetcherMock({ json: { name: "Tom" } });

So, fetch("anyURL") will resolve a response with a json() function that returns { name: "Tom" }.

To resolve the promise, but with different HTTP code do

const fetcher = FetcherMock({ status: 404 });

This will still resolve when you invoke it, but giving you a response object with the status property in 404.

And finally, if you want it to reject (as in a network error) do

const fetcher = FetcherMock({ error: { code: 1, message: "Network error" } });

This will fall into the catch part of the promise, with an error param with code 1 and the message shown above.

LocalStorageMock

This is a HTML 5 window local storage mock, to use in your tests. Just do:

import { LocalStorageMock } from "@luispablo/test-helpers";

...

// and then
const storage = LocalStorageMock();
// and you're done!

Keywords

test

FAQs

Package last updated on 13 Jun 2016

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