jfairbank / redux-saga-test-plan

Test Redux Saga with an easy plan.
http://redux-saga-test-plan.jeremyfairbank.com
MIT License
1.25k stars 127 forks source link

Add support for custom inspect options (depth levels & etc) #366

Closed AdeonMaster closed 3 years ago

AdeonMaster commented 3 years ago

This PR adds support for custom inspect options (depth levels & etc)

Related issues: #95 #339

Example of usage:

import util from 'util';
import testSaga from 'redux-saga-test-plan';
import { put } from 'redux-saga/effects';

const largeAction = {
 type: 'large-action',
 payload: {
  firstLevel: {
   secondLevel: {
     ... // more levels here
   },
  },
 },
};

function* testableSaga() {
 yield put(largeAction)
}

describe('Some sagas to test', () => {
 // this will allow to see the full effect objects while Expected & Actual result comparison in the console 
 util.inspect.defaultOptions.depth = null;

 it('testableSaga', () => {
  testSaga(testableSaga)
   .next()
   .put({
    type: 'large-action',
    payload: { ... },
   })
   .next()
   .isDone();
 });
});
jp928 commented 3 years ago

@AdeonMaster Thanks for your PR. Do you mind to update README as well.

codecov-io commented 3 years ago

Codecov Report

Merging #366 (ac14172) into master (8ddac3c) will increase coverage by 0.00%. The diff coverage is 91.66%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #366   +/-   ##
=======================================
  Coverage   99.60%   99.60%           
=======================================
  Files          22       22           
  Lines         762      763    +1     
  Branches      154      154           
=======================================
+ Hits          759      760    +1     
  Misses          3        3           
Impacted Files Coverage Δ
src/shared/serializeEffect.js 90.00% <66.66%> (ø)
src/expectSaga/expectations.js 98.36% <100.00%> (+0.02%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8ddac3c...ac14172. Read the comment docs.

goncharov commented 2 years ago

@AdeonMaster @jp928 I have a global depth option in the jest setup file but seems it's overwritten when I import redux-saga-test-plan in tests. Can we rework this solution?

AdeonMaster commented 2 years ago

@goncharov Could you please share with us your jest setup file?

goncharov commented 2 years ago

Hi @AdeonMaster Basically my jest setup is

import util from 'util'

util.inspect.defaultOptions.depth = null

Solution I found to not update every test file where redux-saga-test-plan is used is import it in the setup file and set options after. Like this

import util from 'util'
+import 'redux-saga-test-plan'

util.inspect.defaultOptions.depth = null