Redux Reducer中的玩笑覆盖-未涵盖对象破坏

时间:2019-03-22 11:04:54

标签: ecmascript-6 redux jestjs

Jest存在以下问题: 我有这个减速器:

[REMOVE_FILTER]: (state: FiltersState, action: Action<string>): FiltersState => {
    const { [action.payload!]: deleted, ...activeFilters } = state.activeFilters;
    return { ...state, activeFilters, createFilterSelection: undefined, filterCreateOpen: false };
}

当我尝试对其进行测试时,它表示我没有覆盖范围

...activeFilters } = state.activeFilters;

这是我的考试:

test(REMOVE_FILTER, () => {
    const action: IAction<string> = {
        type: REMOVE_FILTER,
        payload: "subprovider"
    };

    expect(
        testReducer({ reducer, state, action })
    ).toEqual({
        ...state,
        activeFilters: { name: null, branded: null },
        createFilterSelection: undefined,
        filterCreateOpen: false
    });
});

有人可以建议我做错了吗?

我正在使用:

  1. 笑话23.6.0
  2. 打字稿3.4.0
  3. Redux 4.0.0
  4. React-Redux:6.0.0
  5. Redux操作:2.6.1

谢谢!

P.S:这是Jest配置:

{
  "coverageThreshold": {
    "global": {
      "branches": 100,
      "functions": 100,
      "lines": 100,
      "statements": 100
    }
  },
  "globals": {
    "window": true,
    "document": true
  },
  "transform": {
    ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
  },
  "testRegex": "(/__test__/.*)\\.test\\.(ts|tsx)$",
  "notify": true,
  "collectCoverageFrom": [
    "**/*.{ts,tsx}"
  ],
  "coveragePathIgnorePatterns": [
    "(/__e2e__/.*)",
    "(/__specs__/.*)",
    "(/__test__/.*)",
    "(/interfaces/.*)",
    "(index.ts)",
    "(src/server/app.ts)",
    "(src/server/config.ts)",
    "(/mock/.*)",
    "(data/mock.ts)",
    "(automapperConfiguration.ts)",
    "(src/app/store/store.ts)",
    "(src/app/containers/brand-configuration/.*)"
  ],
  "moduleFileExtensions": [
    "ts",
    "tsx",
    "js",
    "json"
  ],
  "setupTestFrameworkScriptFile": "<rootDir>/jestSetup.js",
  "testURL": "http://localhost/"
}

上面的TS代码被转译为:

    [REMOVE_FILTER]: (state, action) => {
        const _a = state.activeFilters, _b = action.payload, deleted = _a[_b], activeFilters = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
        return Object.assign({}, state, { activeFilters, createFilterSelection: undefined, filterCreateOpen: false });
    }

0 个答案:

没有答案