我想我找到了解决方案,转到问题的结尾
我对 jasmine-marbles 进行了一个简单的测试,我收到了这个错误,我不知道发生了什么。有任何想法吗?
预期 $[0].notification.kind = 'E' 等于 'N'。
预期 $[0].notification.value = undefined 等于 [ ]。
预期 $[0].notification.error = TypeError:无法读取未定义的属性“池”等于未定义。
预期 $[0].notification.hasValue = false 等于 true。
池管理.component.ts
@Component({
selector: 'app-pool-list',
templateUrl: './pool-list.component.html',
styleUrls: ['./pool-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class PoolListComponent implements OnInit {
pools$ = this.store.pipe(select(selectPools));
constructor(private store: Store<fromPoolManagement.State>) { }
addPool(): void {
this.store.dispatch(PoolManagementActions.addPool({lot: 'XXX', user: 'XYZ', cutDate: new Date().toISOString()}));
}
ngOnInit(): void {
this.store.dispatch(PoolManagementActions.getPools());
}
}
池管理.selectors.ts
export const poolManagementSelector = createFeatureSelector('poolManagement');
export const selectPools = createSelector(
poolManagementSelector,
(state: State) => state.pools
);
池列表.component.spec.ts
fdescribe('PoolListComponent', () => {
let component: PoolListComponent;
let fixture: ComponentFixture<PoolListComponent>;
let mockStore: MockStore<fromPoolManagement.State>;
beforeEach(() => {
const initialState = { pools: [] } as fromPoolManagement.State;
TestBed.configureTestingModule({
declarations: [PoolListComponent],
providers: [provideMockStore({ initialState })],
})
.compileComponents();
fixture = TestBed.createComponent(PoolListComponent);
component = fixture.componentInstance;
mockStore = TestBed.get(Store);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should work, but this test is not working', () => {
const expected = cold('a', { a: []});
expect(component.pools$).toBeObservable(expected);
});
afterEach(() => {
fixture.destroy();
});
});
console.log('预期',预期);