Skip to content

Commit

Permalink
feat(store): adding an internal setting _ngrxMockEnvironment
Browse files Browse the repository at this point in the history
Closes ngrx#2363
  • Loading branch information
evgenyfedorenko committed Mar 2, 2020
1 parent 561610e commit e6fe479
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions modules/store/src/flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let _ngrxMockEnvironment = false;
export function setNgrxMockEnvironment(value: boolean): void {
_ngrxMockEnvironment = value;
}
export function isNgrxMockEnvironment(): boolean {
return _ngrxMockEnvironment;
}
1 change: 1 addition & 0 deletions modules/store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export {
export { createAction, props, union } from './action_creator';
export { Store, select } from './store';
export { combineReducers, compose, createReducerFactory } from './utils';
export { setNgrxMockEnvironment, isNgrxMockEnvironment } from './flags';
export { ActionsSubject, INIT } from './actions_subject';
export {
ReducerManager,
Expand Down
3 changes: 2 additions & 1 deletion modules/store/src/selector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Selector, SelectorWithProps } from './models';
import { isNgrxMockEnvironment } from './flags';
import { isDevMode } from '@angular/core';

export type AnyFn = (...args: any[]) => any;
Expand Down Expand Up @@ -613,7 +614,7 @@ export function createFeatureSelector(
): MemoizedSelector<any, any> {
return createSelector((state: any) => {
const featureState = state[featureName];
if (isDevMode() && !(featureName in state)) {
if (!isNgrxMockEnvironment() && isDevMode() && !(featureName in state)) {
console.warn(
`@ngrx/store: The feature name \"${featureName}\" does ` +
'not exist in the state, therefore createFeatureSelector ' +
Expand Down
2 changes: 2 additions & 0 deletions modules/store/testing/src/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ReducerManager,
StateObservable,
Store,
setNgrxMockEnvironment,
} from '@ngrx/store';
import { MockStore } from './mock_store';
import { MockReducerManager } from './mock_reducer_manager';
Expand All @@ -20,6 +21,7 @@ export interface MockStoreConfig<T> {
export function provideMockStore<T = any>(
config: MockStoreConfig<T> = {}
): Provider[] {
setNgrxMockEnvironment(true);
return [
ActionsSubject,
MockState,
Expand Down

0 comments on commit e6fe479

Please sign in to comment.