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

expectSaga: Attempting to change value of a readonly property #102

Closed akkie closed 7 years ago

akkie commented 7 years ago

I've problems running the following example:

import { put, take } from 'redux-saga/effects';
import { expectSaga } from 'redux-saga-test-plan';

function* mainSaga(x, y) {
  yield take('HELLO');
  yield put({ type: 'ADD', payload: x + y });
  yield take('WORLD');
  yield put({ type: 'DONE' });
}

describe('(Saga) Test', () => {
  it('handles dispatching actions', () => {
    return expectSaga(mainSaga, 40, 2)
    // note that assertions don't have to be in order
      .put({ type: 'DONE' })
      .put({ type: 'ADD', payload: 42 })

      // dispatch any actions your saga will `take`
      // dispatched actions MUST be in order
      .dispatch({ type: 'HELLO' })
      .dispatch({ type: 'WORLD' })

      .run();
  });
});

This is the error:

FAILED TESTS:
  (Saga) Test
    × handles dispatching actions
      PhantomJS 2.1.1 (Windows 7 0.0.0)
    Attempting to change value of a readonly property.
    defineProperty@[native code]
    defineProperty@node_modules/babel-polyfill/dist/polyfill.js:4908:14
    createSagaWrapper@webpack:///~/redux-saga-test-plan/lib/expectSaga/sagaWrapper.js:98:0 <- tests/test-bundler.js:103120:25
    start@webpack:///~/redux-saga-test-plan/lib/expectSaga/index.js:639:0 <- tests/test-bundler.js:100319:50
    run@webpack:///~/redux-saga-test-plan/lib/expectSaga/index.js:665:0 <- tests/test-bundler.js:100345:11
    webpack:///tests/routes/PMM/sagas/FileDeploymentSaga.spec.js:14:0 <- tests/test-bundler.js:375147:66

This issue comes from this line were you try to define a property for the function sagaWrapper.

jfairbank commented 7 years ago

Hi, @akkie!

Thanks for opening this issue.

This looks like an bug with PhantomJS's implementation: issue. Unfortunately, with its maintainer's recent stepping down, I doubt we'll see a fix in PhantomJS.

Redux Saga Test Plan changes the name of the sagaWrapper function to ensure that task names match the name of forked sagas in app code. We'll probably have to wrap that defineProperty call in a try..catch block and possibly put a note in the docs to not depend on the task name property in a PhantomJS environment.

jfairbank commented 7 years ago

@akkie I've published the fix with a try..catch block in v2.4.4. Please let me know if you have any more issues. Thanks!

akkie commented 7 years ago

@jfairbank Thanks :+1: It works as expected!