fix(core): update
This commit is contained in:
parent
b8d0ec55ad
commit
8d296cf08d
@ -36,14 +36,21 @@ tap.test('should select something', async () => {
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should dispatch a state action', async () => {
|
||||
tap.test('should dispatch a state action', async (tools) => {
|
||||
const done = tools.defer();
|
||||
const addFavourite = testStatePart.createAction<string>(async (statePart, payload) => {
|
||||
const currentState = statePart.getState();
|
||||
currentState.currentFavorites.push(payload);
|
||||
return currentState;
|
||||
});
|
||||
testStatePart.waitUntilPresent(state => {
|
||||
return state.currentFavorites[0];
|
||||
}).then(() => {
|
||||
done.resolve();
|
||||
});
|
||||
await testStatePart.dispatchAction(addFavourite, 'my favourite things');
|
||||
expect(testStatePart.getState().currentFavorites).to.include('my favourite things');
|
||||
await done.promise;
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -83,12 +83,13 @@ export class StatePart<TStatePartName, TStatePayload> {
|
||||
public async waitUntilPresent<T = TStatePayload>(selectorFn?: (state: TStatePayload) => T): Promise<T> {
|
||||
const done = plugins.smartpromise.defer<T>();
|
||||
const selectedObservable = this.select(selectorFn);
|
||||
const subscription = selectedObservable.subscribe(value => {
|
||||
const subscription = selectedObservable.subscribe(async value => {
|
||||
if (value) {
|
||||
subscription.unsubscribe();
|
||||
done.resolve(value);
|
||||
}
|
||||
});
|
||||
return await done.promise;
|
||||
const result = await done.promise;
|
||||
subscription.unsubscribe();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user