diff --git a/packages/redux-devtools-test-generator/src/TestGenerator.tsx b/packages/redux-devtools-test-generator/src/TestGenerator.tsx index e2c85934..d8b240f4 100644 --- a/packages/redux-devtools-test-generator/src/TestGenerator.tsx +++ b/packages/redux-devtools-test-generator/src/TestGenerator.tsx @@ -13,18 +13,21 @@ import { AssertionLocals, DispatcherLocals, WrapLocals } from './types'; export const fromPath = (path: (string | number)[]) => path.map((a) => (typeof a === 'string' ? `.${a}` : `[${a}]`)).join(''); -// eslint-disable-next-line @typescript-eslint/ban-types -function getState(s: { state: S; error?: string }, defaultValue: {}) { +function getState( + s: { state: S; error?: string } | undefined, + // eslint-disable-next-line @typescript-eslint/ban-types + defaultValue?: {} +) { if (!s) return defaultValue; return JSON.parse(jsan.stringify(s.state)); } export function compare( - s1: { state: S; error?: string }, + s1: { state: S; error?: string } | undefined, s2: { state: S; error?: string }, cb: (value: { path: string; curState: number | string | undefined }) => void, // eslint-disable-next-line @typescript-eslint/ban-types - defaultValue: {} + defaultValue?: {} ) { const paths: string[] = []; // Already processed function generate( diff --git a/packages/redux-devtools-test-generator/test/TestGenerator.spec.js b/packages/redux-devtools-test-generator/test/TestGenerator.spec.tsx similarity index 82% rename from packages/redux-devtools-test-generator/test/TestGenerator.spec.js rename to packages/redux-devtools-test-generator/test/TestGenerator.spec.tsx index 18167b48..321cd5ce 100644 --- a/packages/redux-devtools-test-generator/test/TestGenerator.spec.js +++ b/packages/redux-devtools-test-generator/test/TestGenerator.spec.tsx @@ -1,28 +1,42 @@ import React from 'react'; import { render } from 'enzyme'; import { renderToJson } from 'enzyme-to-json'; +import { PerformAction } from 'redux-devtools-instrument'; +import { Action } from 'redux'; import TestGenerator from '../src/TestGenerator'; import fnTemplate from '../src/redux/mocha'; import strTemplate from '../src/redux/mocha/template'; import fnVanillaTemplate from '../src/vanilla/mocha'; import strVanillaTemplate from '../src/vanilla/mocha/template'; -const actions = { - 0: { type: 'PERFORM_ACTION', action: { type: '@@INIT' } }, - 1: { type: 'PERFORM_ACTION', action: { type: 'INCREMENT_COUNTER' } }, +const actions: { [actionId: number]: PerformAction> } = { + 0: { + type: 'PERFORM_ACTION', + action: { type: '@@INIT' }, + timestamp: 0, + stack: undefined, + }, + 1: { + type: 'PERFORM_ACTION', + action: { type: 'INCREMENT_COUNTER' }, + timestamp: 0, + stack: undefined, + }, }; const computedStates = [{ state: { counter: 0 } }, { state: { counter: 1 } }]; +const TestGeneratorAsAny = TestGenerator as any; + describe('TestGenerator component', () => { it('should show warning message when no params provided', () => { - const component = render(); + const component = render(); expect(renderToJson(component)).toMatchSnapshot(); }); it('should be empty when no actions provided', () => { const component = render( - { it("should match function template's test for first action", () => { const component = render( - { it("should match string template's test for first action", () => { const component = render( - { it('should generate test for the last action when selectedActionId not specified', () => { const component = render( - { it('should generate test for vanilla js class', () => { const component = render( - { it('should generate test for vanilla js class with string template', () => { const component = render( - +const test = (s1: { state: unknown } | undefined, s2: { state: unknown }) => compare(s1, s2, ({ path, curState }) => - expect(`expect(store${path}).toEqual(${curState});`).toBe( - assertion({ path, curState }) - ) + expect( + `expect(store${path}).toEqual(${curState as number | string});` + ).toBe(assertion({ path, curState })) ); describe('Assertions', () => { diff --git a/packages/redux-devtools-test-generator/test/setup.js b/packages/redux-devtools-test-generator/test/setup.ts similarity index 100% rename from packages/redux-devtools-test-generator/test/setup.js rename to packages/redux-devtools-test-generator/test/setup.ts