mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-22 22:19:48 +03:00
Tests
This commit is contained in:
parent
1d6d3867d2
commit
407a5bac43
|
@ -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>(s: { state: S; error?: string }, defaultValue: {}) {
|
||||
function getState<S>(
|
||||
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<S>(
|
||||
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(
|
||||
|
|
|
@ -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<Action<unknown>> } = {
|
||||
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(<TestGenerator useCodemirror={false} />);
|
||||
const component = render(<TestGeneratorAsAny useCodemirror={false} />);
|
||||
expect(renderToJson(component)).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should be empty when no actions provided', () => {
|
||||
const component = render(
|
||||
<TestGenerator
|
||||
<TestGeneratorAsAny
|
||||
assertion={fnTemplate.assertion}
|
||||
dispatcher={fnTemplate.dispatcher}
|
||||
wrap={fnTemplate.wrap}
|
||||
|
@ -34,7 +48,7 @@ describe('TestGenerator component', () => {
|
|||
|
||||
it("should match function template's test for first action", () => {
|
||||
const component = render(
|
||||
<TestGenerator
|
||||
<TestGeneratorAsAny
|
||||
assertion={fnTemplate.assertion}
|
||||
dispatcher={fnTemplate.dispatcher}
|
||||
wrap={fnTemplate.wrap}
|
||||
|
@ -49,7 +63,7 @@ describe('TestGenerator component', () => {
|
|||
|
||||
it("should match string template's test for first action", () => {
|
||||
const component = render(
|
||||
<TestGenerator
|
||||
<TestGeneratorAsAny
|
||||
assertion={strTemplate.assertion}
|
||||
dispatcher={strTemplate.dispatcher}
|
||||
wrap={strTemplate.wrap}
|
||||
|
@ -64,7 +78,7 @@ describe('TestGenerator component', () => {
|
|||
|
||||
it('should generate test for the last action when selectedActionId not specified', () => {
|
||||
const component = render(
|
||||
<TestGenerator
|
||||
<TestGeneratorAsAny
|
||||
assertion={fnTemplate.assertion}
|
||||
dispatcher={fnTemplate.dispatcher}
|
||||
wrap={fnTemplate.wrap}
|
||||
|
@ -78,7 +92,7 @@ describe('TestGenerator component', () => {
|
|||
|
||||
it('should generate test for vanilla js class', () => {
|
||||
const component = render(
|
||||
<TestGenerator
|
||||
<TestGeneratorAsAny
|
||||
assertion={fnVanillaTemplate.assertion}
|
||||
dispatcher={fnVanillaTemplate.dispatcher}
|
||||
wrap={fnVanillaTemplate.wrap}
|
||||
|
@ -95,7 +109,7 @@ describe('TestGenerator component', () => {
|
|||
|
||||
it('should generate test for vanilla js class with string template', () => {
|
||||
const component = render(
|
||||
<TestGenerator
|
||||
<TestGeneratorAsAny
|
||||
assertion={strVanillaTemplate.assertion}
|
||||
dispatcher={strVanillaTemplate.dispatcher}
|
||||
wrap={strVanillaTemplate.wrap}
|
|
@ -12,11 +12,11 @@ const computedStates = [
|
|||
{ state: [0, 2, 3, 4] },
|
||||
];
|
||||
|
||||
const test = (s1, s2) =>
|
||||
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', () => {
|
Loading…
Reference in New Issue
Block a user