我該如何訂閱後去得知 type 是不是 decrement
// decrementAsync.js
import { of } from 'rxjs';
import { delay, filter } from 'rxjs/operators';
export const decrementAsync = ({ dispatch }) => {
of(null)
.pipe(delay(1000))
.subscribe(() => dispatch('decrement'));
};
// decrementAsync.spec.js
import { marbles } from 'rxjs-marbles/jest';
import { decrementAsync } from './decrementAsync';
describe('decrementAsync', () => {
it('should handle decrementAsync', marbles((m) => {
const dispatch = (type) => {
const source = m.hot('--^-a-----|', { a: null });
const subs = '^-------!';
const expected = '---a----|';
const destination = source.pipe(delay(m.time('-|')));
m.expect(destination).toBeObservable(expected);
m.expect(source).toHaveSubscriptions(subs);
m.expect(type).toBe('decrement');
};
decrementAsync({ dispatch });
}));
});