Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Jest tests #32

Open
bellmoose opened this issue Mar 14, 2018 · 1 comment
Open

Issue with Jest tests #32

bellmoose opened this issue Mar 14, 2018 · 1 comment

Comments

@bellmoose
Copy link

The transform works well when I use it in my application, but it fails when running my unit tests declaring that it is not a function. Is there a specific setup step that needs to be performed when using Jest?

@ChildishDanbino
Copy link

ChildishDanbino commented Apr 9, 2018

@bellmoose - You didn't provide much info on what your code looks like but I was running into the same issue so i'll try and walk you through it as well as leave this here for others:

When you create a transform you are getting back an object that has three functions not a function itself.... Inbound, Outbound, and Config. Depending on your transform you'll need to test them individually. Below is my code for a really simple transform that blacklists "account.loading" from being persisted.

Transform:


export const accountBlackList = createTransform(
  (reducer, key) => {
    if (key !== 'account') {
      return reducer;
    }
    return {
      ...reducer,
      loading: undefined
    };
  }
);

export default accountBlackList;

Unit Test with 100% Coverage:

import { accountBlackList } from '../../../src/redux/transforms/account';
import { initialState } from '../../../src/redux/modules/account';

describe('transforms: account', () => {
  it('should return loading undefined for account reducer', () => {
    const result = accountBlackList.in(initialState, 'account');
    expect(result.loading).toEqual(undefined);
  });

  it('should return reducer as in when not account', () => {
    const result = accountBlackList.in(initialState, 'prices');
    expect(result).toEqual(initialState);
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants