jambit / eslint-plugin-typed-redux-saga

These are eslint rules to help with typed-redux-saga
MIT License
17 stars 3 forks source link

Ability to prevent using typed-redux-saga for tests #9

Open krutoo opened 1 year ago

krutoo commented 1 year ago

Hi can you add option to forbid using typed-redux-saga and typed-redux-saga/macro?

Here is example of saga:

import { call } from 'typed-redux-saga/macro';

function saga() {
  yield* call(myFunction);
}

I want to use typed-redux-saga/macro only in source code of application and redux-saga/effects only in tests.

Bcause tests like this:

import { call } from 'typed-redux-saga/macro';
import { saga } from '../saga';

it('test', () => {
  const gen = saga();
  expect(gen.next().value).toEqual(call(myFunction));
});

are misleading.

In this case call effect are delegated by yield* and the correct check should be:

expect(gen.next().value).toEqual(call(myFunction).next().value);
feidaZhang commented 1 year ago
// jest.config
  transform: {
    '^.+\\.js(x)?$': 'babel-jest',
    '^.+\\.ts(x)?$': 'babel-jest',
    '^.+\\.ts(x)?$': [
      'ts-jest',
      {
        tsconfig: 'tsconfig.spec.json',
      },
    ],
  },

// ut 
import {testSaga} from 'redux-saga-test-plan';
import {initialRealm, initialSaga} from '~store/sagas/initial';

test('initialSaga', () => {
  testSaga(initialSaga).next().call(initialRealm).next().isDone();
});
krutoo commented 1 year ago

@feidaZhang But in your example there is no eslint