@@ -173,187 +173,6 @@ describe('createFeature()', () => {
173
173
} ) ;
174
174
} ) ;
175
175
176
- describe ( 'with passed app state type' , ( ) => {
177
- it ( 'should create' , ( ) => {
178
- const snippet = expectSnippet ( `
179
- const enter = createAction('[Books Page] Enter');
180
- const loadBooksSuccess = createAction(
181
- '[Books API] Load Books Success',
182
- props<{ books: Book[] }>()
183
- );
184
-
185
- interface Book {
186
- id: number;
187
- title: string;
188
- }
189
-
190
- type LoadState = 'init' | 'loading' | 'loaded' | 'error';
191
-
192
- interface BooksState {
193
- books: Book[];
194
- loadState: LoadState;
195
- }
196
-
197
- interface AppState {
198
- books: BooksState;
199
- }
200
-
201
- const initialState: BooksState = {
202
- books: [],
203
- loadState: 'init',
204
- };
205
-
206
- const booksFeature = createFeature<AppState>({
207
- name: 'books',
208
- reducer: createReducer(
209
- initialState,
210
- on(enter, (state) => ({ ...state, loadState: 'loading' })),
211
- on(loadBooksSuccess, (state, { books }) => ({
212
- ...state,
213
- books,
214
- loadState: 'loaded',
215
- }))
216
- ),
217
- });
218
-
219
- const {
220
- name,
221
- reducer,
222
- selectBooksState,
223
- selectBooks,
224
- selectLoadState,
225
- } = booksFeature;
226
-
227
- let booksFeatureKeys: keyof typeof booksFeature;
228
- ` ) ;
229
-
230
- snippet . toInfer ( 'name' , '"books"' ) ;
231
- snippet . toInfer ( 'reducer' , 'ActionReducer<BooksState, Action>' ) ;
232
- snippet . toInfer (
233
- 'selectBooksState' ,
234
- 'MemoizedSelector<AppState, BooksState, (featureState: BooksState) => BooksState>'
235
- ) ;
236
- snippet . toInfer (
237
- 'selectBooks' ,
238
- 'MemoizedSelector<AppState, Book[], (featureState: BooksState) => Book[]>'
239
- ) ;
240
- snippet . toInfer (
241
- 'selectLoadState' ,
242
- 'MemoizedSelector<AppState, LoadState, (featureState: BooksState) => LoadState>'
243
- ) ;
244
- snippet . toInfer (
245
- 'booksFeatureKeys' ,
246
- '"selectBooksState" | "selectBooks" | "selectLoadState" | keyof FeatureConfig<"books", BooksState>'
247
- ) ;
248
- } ) ;
249
-
250
- it ( 'should create a feature when reducer is created outside' , ( ) => {
251
- const snippet = expectSnippet ( `
252
- interface State {
253
- bar: string;
254
- }
255
- const initialState: State = { bar: 'ngrx' };
256
-
257
- const fooReducer = createReducer(initialState);
258
- const fooFeature = createFeature<{ foo: State }>({
259
- name: 'foo',
260
- reducer: fooReducer,
261
- });
262
-
263
- const {
264
- name,
265
- reducer,
266
- selectFooState,
267
- selectBar,
268
- } = fooFeature;
269
- ` ) ;
270
-
271
- snippet . toInfer ( 'name' , '"foo"' ) ;
272
- snippet . toInfer ( 'reducer' , 'ActionReducer<State, Action>' ) ;
273
- snippet . toInfer (
274
- 'selectFooState' ,
275
- 'MemoizedSelector<{ foo: State; }, State, (featureState: State) => State>'
276
- ) ;
277
- snippet . toInfer (
278
- 'selectBar' ,
279
- 'MemoizedSelector<{ foo: State; }, string, (featureState: State) => string>'
280
- ) ;
281
- } ) ;
282
-
283
- it ( 'should fail when name is not key of app state' , ( ) => {
284
- expectSnippet ( `
285
- interface AppState {
286
- counter1: number;
287
- counter2: number;
288
- }
289
-
290
- const counterFeature = createFeature<AppState>({
291
- name: 'counter3',
292
- reducer: createReducer(0),
293
- });
294
- ` ) . toFail (
295
- / T y p e ' " c o u n t e r 3 " ' i s n o t a s s i g n a b l e t o t y p e ' " c o u n t e r 1 " | " c o u n t e r 2 " ' /
296
- ) ;
297
- } ) ;
298
-
299
- it ( 'should allow use with StoreModule.forFeature' , ( ) => {
300
- expectSnippet ( `
301
- const counterFeature = createFeature<{ counter: number }>({
302
- name: 'counter',
303
- reducer: createReducer(0),
304
- });
305
-
306
- StoreModule.forFeature(counterFeature);
307
- ` ) . toSucceed ( ) ;
308
- } ) ;
309
-
310
- it ( 'should allow use with untyped store.select' , ( ) => {
311
- expectSnippet ( `
312
- const { selectCounterState, selectCount } = createFeature<{ counter: { count: number } }>({
313
- name: 'counter',
314
- reducer: createReducer({ count: 0 }),
315
- });
316
-
317
- let store!: Store;
318
- const counterState$ = store.select(selectCounterState);
319
- const count$ = store.select(selectCount);
320
- ` ) . toFail (
321
- / T y p e ' o b j e c t ' i s n o t a s s i g n a b l e t o t y p e ' { c o u n t e r : { c o u n t : n u m b e r ; } ; } ' /
322
- ) ;
323
- } ) ;
324
-
325
- it ( 'should allow use with typed store.select' , ( ) => {
326
- const snippet = expectSnippet ( `
327
- const { selectCounterState } = createFeature<{ counter: number }>({
328
- name: 'counter',
329
- reducer: createReducer(0),
330
- });
331
-
332
- let store!: Store<{ counter: number }>;
333
- const counterState$ = store.select(selectCounterState);
334
- ` ) ;
335
-
336
- snippet . toInfer ( 'counterState$' , 'Observable<number>' ) ;
337
- } ) ;
338
-
339
- it ( 'should fail when feature state contains optional properties' , ( ) => {
340
- expectSnippet ( `
341
- interface CounterState {
342
- count?: number;
343
- }
344
-
345
- interface AppState {
346
- counter: CounterState;
347
- }
348
-
349
- const counterFeature = createFeature<AppState>({
350
- name: 'counter',
351
- reducer: createReducer({} as CounterState),
352
- });
353
- ` ) . toFail ( / o p t i o n a l p r o p e r t i e s a r e n o t a l l o w e d i n t h e f e a t u r e s t a t e / ) ;
354
- } ) ;
355
- } ) ;
356
-
357
176
describe ( 'nested selectors' , ( ) => {
358
177
it ( 'should not create with feature state as a primitive value' , ( ) => {
359
178
expectSnippet ( `
0 commit comments