| 1 |
import type { StoreEnhancer } from '@reduxjs/toolkit' |
| 2 |
import { configureStore } from '@reduxjs/toolkit' |
| 3 |
|
| 4 |
declare const enhancer1: StoreEnhancer< |
| 5 |
{ |
| 6 |
has1: true |
| 7 |
}, |
| 8 |
{ stateHas1: true } |
| 9 |
> |
| 10 |
|
| 11 |
declare const enhancer2: StoreEnhancer< |
| 12 |
{ |
| 13 |
has2: true |
| 14 |
}, |
| 15 |
{ stateHas2: true } |
| 16 |
> |
| 17 |
|
| 18 |
describe('type tests', () => { |
| 19 |
test('prepend single element', () => { |
| 20 |
const store = configureStore({ |
| 21 |
reducer: () => 0, |
| 22 |
enhancers: (gDE) => gDE().prepend(enhancer1), |
| 23 |
}) |
| 24 |
|
| 25 |
expectTypeOf(store.has1).toEqualTypeOf<true>() |
| 26 |
|
| 27 |
expectTypeOf(store.getState().stateHas1).toEqualTypeOf<true>() |
| 28 |
|
| 29 |
expectTypeOf(store).not.toHaveProperty('has2') |
| 30 |
|
| 31 |
expectTypeOf(store.getState()).not.toHaveProperty('stateHas2') |
| 32 |
}) |
| 33 |
|
| 34 |
test('prepend multiple (rest)', () => { |
| 35 |
const store = configureStore({ |
| 36 |
reducer: () => 0, |
| 37 |
enhancers: (gDE) => gDE().prepend(enhancer1, enhancer2), |
| 38 |
}) |
| 39 |
|
| 40 |
expectTypeOf(store.has1).toEqualTypeOf<true>() |
| 41 |
|
| 42 |
expectTypeOf(store.getState().stateHas1).toEqualTypeOf<true>() |
| 43 |
|
| 44 |
expectTypeOf(store.has2).toEqualTypeOf<true>() |
| 45 |
|
| 46 |
expectTypeOf(store.getState().stateHas2).toEqualTypeOf<true>() |
| 47 |
|
| 48 |
expectTypeOf(store).not.toHaveProperty('has3') |
| 49 |
|
| 50 |
expectTypeOf(store.getState()).not.toHaveProperty('stateHas3') |
| 51 |
}) |
| 52 |
|
| 53 |
test('prepend multiple (array notation)', () => { |
| 54 |
const store = configureStore({ |
| 55 |
reducer: () => 0, |
| 56 |
enhancers: (gDE) => gDE().prepend([enhancer1, enhancer2] as const), |
| 57 |
}) |
| 58 |
|
| 59 |
expectTypeOf(store.has1).toEqualTypeOf<true>() |
| 60 |
|
| 61 |
expectTypeOf(store.getState().stateHas1).toEqualTypeOf<true>() |
| 62 |
|
| 63 |
expectTypeOf(store.has2).toEqualTypeOf<true>() |
| 64 |
|
| 65 |
expectTypeOf(store.getState().stateHas2).toEqualTypeOf<true>() |
| 66 |
|
| 67 |
expectTypeOf(store).not.toHaveProperty('has3') |
| 68 |
|
| 69 |
expectTypeOf(store.getState()).not.toHaveProperty('stateHas3') |
| 70 |
}) |
| 71 |
|
| 72 |
test('concat single element', () => { |
| 73 |
const store = configureStore({ |
| 74 |
reducer: () => 0, |
| 75 |
enhancers: (gDE) => gDE().concat(enhancer1), |
| 76 |
}) |
| 77 |
|
| 78 |
expectTypeOf(store.has1).toEqualTypeOf<true>() |
| 79 |
|
| 80 |
expectTypeOf(store.getState().stateHas1).toEqualTypeOf<true>() |
| 81 |
|
| 82 |
expectTypeOf(store).not.toHaveProperty('has2') |
| 83 |
|
| 84 |
expectTypeOf(store.getState()).not.toHaveProperty('stateHas2') |
| 85 |
}) |
| 86 |
|
| 87 |
test('prepend multiple (rest)', () => { |
| 88 |
const store = configureStore({ |
| 89 |
reducer: () => 0, |
| 90 |
enhancers: (gDE) => gDE().concat(enhancer1, enhancer2), |
| 91 |
}) |
| 92 |
|
| 93 |
expectTypeOf(store.has1).toEqualTypeOf<true>() |
| 94 |
|
| 95 |
expectTypeOf(store.getState().stateHas1).toEqualTypeOf<true>() |
| 96 |
|
| 97 |
expectTypeOf(store.has2).toEqualTypeOf<true>() |
| 98 |
|
| 99 |
expectTypeOf(store.getState().stateHas2).toEqualTypeOf<true>() |
| 100 |
|
| 101 |
expectTypeOf(store).not.toHaveProperty('has3') |
| 102 |
|
| 103 |
expectTypeOf(store.getState()).not.toHaveProperty('stateHas3') |
| 104 |
}) |
| 105 |
|
| 106 |
test('concat multiple (array notation)', () => { |
| 107 |
const store = configureStore({ |
| 108 |
reducer: () => 0, |
| 109 |
enhancers: (gDE) => gDE().concat([enhancer1, enhancer2] as const), |
| 110 |
}) |
| 111 |
|
| 112 |
expectTypeOf(store.has1).toEqualTypeOf<true>() |
| 113 |
|
| 114 |
expectTypeOf(store.getState().stateHas1).toEqualTypeOf<true>() |
| 115 |
|
| 116 |
expectTypeOf(store.has2).toEqualTypeOf<true>() |
| 117 |
|
| 118 |
expectTypeOf(store.getState().stateHas2).toEqualTypeOf<true>() |
| 119 |
|
| 120 |
expectTypeOf(store).not.toHaveProperty('has3') |
| 121 |
|
| 122 |
expectTypeOf(store.getState()).not.toHaveProperty('stateHas3') |
| 123 |
}) |
| 124 |
|
| 125 |
test('concat and prepend', () => { |
| 126 |
const store = configureStore({ |
| 127 |
reducer: () => 0, |
| 128 |
enhancers: (gDE) => gDE().concat(enhancer1).prepend(enhancer2), |
| 129 |
}) |
| 130 |
|
| 131 |
expectTypeOf(store.has1).toEqualTypeOf<true>() |
| 132 |
|
| 133 |
expectTypeOf(store.getState().stateHas1).toEqualTypeOf<true>() |
| 134 |
|
| 135 |
expectTypeOf(store.has2).toEqualTypeOf<true>() |
| 136 |
|
| 137 |
expectTypeOf(store.getState().stateHas2).toEqualTypeOf<true>() |
| 138 |
|
| 139 |
expectTypeOf(store).not.toHaveProperty('has3') |
| 140 |
|
| 141 |
expectTypeOf(store.getState()).not.toHaveProperty('stateHas3') |
| 142 |
}) |
| 143 |
}) |