Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-jest-helper

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-jest-helper - npm Package Compare versions

Comparing version 0.0.3 to 1.0.1

15

dist/middleware-factory.d.ts

@@ -1,11 +0,8 @@

import { Action, Dispatch, Middleware, MiddlewareAPI } from 'redux';
export interface ExtendedMiddleware<T> extends Middleware {
<S extends T>(api: MiddlewareAPI<S>): (next: Dispatch<S>) => Dispatch<S>;
}
export declare abstract class MiddlewareFactory<S> {
import { Action, Dispatch, MiddlewareAPI, Middleware, AnyAction } from 'redux';
export declare abstract class MiddlewareFactory<S, D extends Dispatch = Dispatch, A extends Action = AnyAction> {
[key: string]: any;
onBeforeAction?: (api: MiddlewareAPI<S>, action: Action) => void;
onAfterAction?: (api: MiddlewareAPI<S>, action: Action, prevState: S) => void;
onCreateMiddleware?: (api: MiddlewareAPI<S>) => void;
toMiddleware: () => ExtendedMiddleware<S>;
onBeforeAction?: (api: MiddlewareAPI<D, S>, action: A) => void;
onAfterAction?: (api: MiddlewareAPI<D, S>, action: A, prevState: S) => void;
onCreateMiddleware?: (api: MiddlewareAPI<D, S>) => void;
toMiddleware: () => Middleware<{}, S, D>;
}

2

dist/middleware-factory.js

@@ -10,3 +10,3 @@ "use strict";

}
return (next) => (action) => {
return next => action => {
if (this.onBeforeAction) {

@@ -13,0 +13,0 @@ this.onBeforeAction(api, action);

@@ -0,1 +1,2 @@

import { Dispatch, AnyAction } from 'redux';
import { MiddlewareFactory } from './middleware-factory';

@@ -6,2 +7,2 @@ export interface ActionTypeToMethod {

}
export declare const middlewareTestHelper: <T>(cut: MiddlewareFactory<T>, actionTypes: ActionTypeToMethod[]) => void;
export declare const middlewareTestHelper: <T>(cut: MiddlewareFactory<T, Dispatch<AnyAction>, AnyAction>, actionTypes: ActionTypeToMethod[]) => void;

@@ -1,6 +0,6 @@

import { Action } from 'redux';
export declare abstract class ReducerFactory<S> {
import { Action, AnyAction } from 'redux';
export declare abstract class ReducerFactory<S, A extends Action = AnyAction> {
[key: string]: any;
onAction: (state: S | undefined, action: Action) => S;
toReducer: () => (state: S | undefined, action: Action) => S;
onAction: (state: S | undefined, action: A) => S;
toReducer: () => (state: S | undefined, action: A) => S;
}
import { ReducerFactory } from './reducer-factory';
import { AnyAction } from 'redux';
export interface ActionTypeToMethod {

@@ -7,2 +8,2 @@ actionType: string;

}
export declare const reducerTestHelper: <T>(cut: ReducerFactory<T>, initialState: T, actionTypes: ActionTypeToMethod[]) => void;
export declare const reducerTestHelper: <T>(cut: ReducerFactory<T, AnyAction>, initialState: T, actionTypes: ActionTypeToMethod[]) => void;
{
"name": "redux-jest-helper",
"version": "0.0.3",
"description": "Provides easily testable classes that genrate redux-middlewares or -reducers",
"version": "1.0.1",
"description": "Provides easily testable classes that generate redux-middlewares or -reducers",
"author": "patsimm",

@@ -18,3 +18,3 @@ "license": "MIT",

"peerDependencies": {
"redux": ">=3.0.0",
"redux": ">=4.0.0",
"jest": ">=20.0.0"

@@ -26,3 +26,3 @@ },

"jest": "^22.1.4",
"redux": "^3.7.2",
"redux": "^4.0.0",
"ts-jest": "^22.0.2",

@@ -29,0 +29,0 @@ "typescript": "^2.7.1"

@@ -5,2 +5,14 @@ # ReduxJestHelper

## Installation
Using yarn you only need to execute
```
yarn add redux-jest-helper
```
or if you are using npm, execute
```
npm install redux-jest-helper --save
```
## Usage

@@ -7,0 +19,0 @@

@@ -1,19 +0,15 @@

import { Action, Dispatch, Middleware, MiddlewareAPI } from 'redux'
import { Action, Dispatch, MiddlewareAPI, Middleware, AnyAction } from 'redux'
export interface ExtendedMiddleware<T> extends Middleware {
<S extends T>(api: MiddlewareAPI<S>): (next: Dispatch<S>) => Dispatch<S>
}
export abstract class MiddlewareFactory<S> {
export abstract class MiddlewareFactory<S, D extends Dispatch = Dispatch, A extends Action = AnyAction> {
[key: string]: any
onBeforeAction?: (api: MiddlewareAPI<S>, action: Action) => void
onAfterAction?: (api: MiddlewareAPI<S>, action: Action, prevState: S) => void
onCreateMiddleware?: (api: MiddlewareAPI<S>) => void
onBeforeAction?: (api: MiddlewareAPI<D, S>, action: A) => void
onAfterAction?: (api: MiddlewareAPI<D, S>, action: A, prevState: S) => void
onCreateMiddleware?: (api: MiddlewareAPI<D, S>) => void
toMiddleware = (): ExtendedMiddleware<S> => {
return (api: MiddlewareAPI<S>) => {
toMiddleware = (): Middleware<{}, S, D> => {
return (api: MiddlewareAPI<D, S>) => {
if (this.onCreateMiddleware) {
this.onCreateMiddleware(api)
}
return (next: Dispatch<S>) => (action: Action): any => {
return next => action => {
if (this.onBeforeAction) {

@@ -20,0 +16,0 @@ this.onBeforeAction(api, action)

import { MiddlewareFactory } from './middleware-factory'
import { MiddlewareAPI, Action } from 'redux'
import { MiddlewareAPI, Action, Dispatch } from 'redux'
import { middlewareTestHelper } from './middleware-test-helper'

@@ -33,3 +33,3 @@

onBeforeAction = (api: MiddlewareAPI<TestState>, action: Action) => {
onBeforeAction = (api: MiddlewareAPI<Dispatch>, action: Action) => {
switch (action.type) {

@@ -45,3 +45,3 @@ case ActionType.INCREMENT:

onAfterAction = (api: MiddlewareAPI<TestState>, action: Action, prevState: TestState) => {
onAfterAction = (api: MiddlewareAPI<Dispatch>, action: Action, prevState: TestState) => {
switch (action.type) {

@@ -48,0 +48,0 @@ case ActionType.INCREMENT:

@@ -1,2 +0,2 @@

import { Action, Dispatch, Store } from 'redux'
import { Dispatch, Store, AnyAction } from 'redux'

@@ -25,4 +25,4 @@ import { MiddlewareFactory } from './middleware-factory'

}
let next: Dispatch<any>
let action: Action
let next: Dispatch
let action: AnyAction

@@ -29,0 +29,0 @@ beforeEach(() => {

@@ -1,9 +0,9 @@

import { Action } from 'redux'
import { Action, AnyAction } from 'redux'
export abstract class ReducerFactory<S> {
export abstract class ReducerFactory<S, A extends Action = AnyAction> {
[key: string]: any
onAction: (state: S | undefined, action: Action) => S
onAction: (state: S | undefined, action: A) => S
toReducer = (): ((state: S | undefined, action: Action) => S) => {
return (state: S | undefined, action: Action): S => {
toReducer = (): ((state: S | undefined, action: A) => S) => {
return (state: S | undefined, action: A): S => {
return this.onAction(state, action)

@@ -10,0 +10,0 @@ }

import * as deepFreeze from 'deep-freeze'
import { Action } from 'redux'
import { ReducerFactory } from './reducer-factory'
import { AnyAction } from 'redux';

@@ -19,3 +19,3 @@ export interface ActionTypeToMethod {

const reducer = cut.toReducer()
let action: Action
let action: AnyAction

@@ -22,0 +22,0 @@ beforeEach(() => {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc