Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bar: {
a: {
b: {
c: {
d: 'world'
}
}
}
}
}
};
const msFeature = createFeatureSelector('myFeature');
const msBar = createSelector(msFeature, state => state.bar);
const store = new Store(of(globalState), undefined as any, undefined as any);
it('selects sub state with Select decorator', () => {
NgrxSelect.store = store;
class MyStateSelector {
@Select(msBar) bar$: Observable; // using MemoizedSelector
}
const mss = new MyStateSelector();
mss.bar$.subscribe(n => {
expect(n).toBe(globalState.myFeature.bar);
});
});
it('should apply pipeable operator when provided', () => {
NgrxSelect.store = store;
}
}
};
const msFeature = createFeatureSelector('myFeature');
const msBar = createSelector(msFeature, state => state.bar);
class MyStateSelector {
@Select('myFeature.bar.a.b.c.d') hello$: Observable; // deeply nested props
@Select() myFeature: Observable; // implied by name
@Select(msBar) bar$: Observable; // using MemoizedSelector
@Select(state => [])
bar2$: Observable; // Remapping to different obj
}
const store = new NgRxStore(of(globalState), undefined, undefined);
try {
NgrxSelect.store = store;
const mss = new MyStateSelector();
mss.hello$.subscribe(n => {
expect(n).toBe('world');
});
mss.myFeature.subscribe(n => {
expect(n).toBe(globalState.myFeature);
});
mss.bar2$.subscribe(n => {
expect(n.length).toBe(0);
beforeEach(() => {
init();
store = new Store(undefined, undefined, undefined);
spyOn(store, 'dispatch');
service = new ObjectCacheService(store);
spyOn(Date.prototype, 'getTime').and.callFake(() => {
return timestamp;
});
});
bar: {
a: {
b: {
c: {
d: 'world'
}
}
}
}
}
};
const msFeature = createFeatureSelector('myFeature');
const msBar = createSelector(msFeature, state => state.bar);
const store = new Store(of(globalState), undefined as any, undefined as any);
afterEach(() => {
NgrxSelect.store = undefined;
});
describe('modules', () => {
it('should create module', () => {
const ngrxSelect = new NgrxSelect();
spyOn(ngrxSelect, 'connect').and.callThrough();
expect(ngrxSelect).toBeTruthy();
expect(new NgrxUtilsModule(ngrxSelect, store)).toBeTruthy();
expect(ngrxSelect.connect).toHaveBeenCalled();
expect(NgrxSelect.store).toEqual(store);
});
});
describe('NgrxSelectModule', () => {
const store = new Store(of({}), undefined as any, undefined as any);
afterEach(() => {
NgrxSelect.store = undefined;
});
describe('modules', () => {
it('should create module', () => {
const ngrxSelect = new NgrxSelect();
spyOn(ngrxSelect, 'connect').and.callThrough();
expect(ngrxSelect).toBeTruthy();
const module = new NgrxSelectModule(ngrxSelect, store, undefined as any);
expect(module).toBeTruthy();
expect(ngrxSelect.connect).toHaveBeenCalled();
expect(NgrxSelect.store).toEqual(store);
expect(() => new NgrxSelectModule(ngrxSelect, store, {})).toThrowError();
});
describe('Dispatch', () => {
const store = new Store(of({}), new ActionsSubject(), undefined as any);
const action1 = { type: 'test-action1' };
const action2 = { type: 'test-action2' };
it('should dispatch action', () => {
spyOn(store, 'dispatch').and.callThrough();
NgrxSelect.store = store;
class TestComponent {
@Dispatch()
onAction() {
return action1;
}
}
const testComp = new TestComponent();
testComp.onAction();
expect(store.dispatch).toHaveBeenCalledWith(action1);
beforeEach(() => {
const _initialState = { hostWindow: { width: 1100, height: 770 } };
store = new Store(observableOf(_initialState), undefined, undefined);
service = new HostWindowService(store);
});
beforeEach(() => {
store = new Store(undefined, undefined, undefined);
spyOn(store, 'dispatch');
service = new RequestCacheService(store);
spyOn(window, 'Date').and.returnValue({ getTime: () => timestamp });
});
beforeEach(() => {
scheduler = getTestScheduler();
objectCache = getMockObjectCacheService();
(objectCache.hasBySelfLink as any).and.returnValue(false);
uuidService = getMockUUIDService();
store = new Store(new BehaviorSubject({}), new ActionsSubject(), null);
selectSpy = spyOnProperty(ngrx, 'select');
selectSpy.and.callFake(() => {
return () => {
return () => cold('a', { a: undefined });
};
});
service = new RequestService(
objectCache,
uuidService,
store,
undefined
);
serviceAsAny = service as any;
});
beforeEach(() => {
store = new Store(undefined, undefined, undefined);
spyOn(store, 'dispatch');
objectCacheService = new ObjectCacheService(store);
uuidService = new UUIDService();
requestService = new RequestService(objectCacheService, uuidService, store, undefined);
remoteDataBuildService = new RemoteDataBuildService(objectCacheService, requestService);
TestBed.configureTestingModule({
imports: [
CommonModule,
StoreModule.forRoot({}),
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: MockTranslateLoader
}