From c26cf191a41f2e49990f7f06966fddc9fa1ce758 Mon Sep 17 00:00:00 2001 From: Mikhail Nasyrov Date: Sun, 25 Jul 2021 21:10:34 +0700 Subject: [PATCH] test: Increased the coverage. Dropped testing with old node.js versions. --- .github/workflows/main.yml | 22 +--------------------- packages/rx-effects/src/effect.test.ts | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5938d7f..2dfd60d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta + - uses: actions/setup-node@v2 with: node-version: '16' - name: Install dependencies @@ -24,23 +24,3 @@ jobs: uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} - - test-compatibility: - needs: test - runs-on: ubuntu-latest - strategy: - matrix: - node: ['12', '14', '16'] - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta - with: - node-version: ${{ matrix.node }} - - name: Install dependencies - run: npm ci - - name: Build - run: npm run build - - name: Lint - run: npm run lint - - name: Test - run: npm run test diff --git a/packages/rx-effects/src/effect.test.ts b/packages/rx-effects/src/effect.test.ts index b6f8cbf..ded646b 100644 --- a/packages/rx-effects/src/effect.test.ts +++ b/packages/rx-effects/src/effect.test.ts @@ -6,6 +6,7 @@ import { of, tap, throwError, + timeout, timer, } from 'rxjs'; import { switchMap, take, toArray } from 'rxjs/operators'; @@ -164,14 +165,29 @@ describe('Effect', () => { const effect = createEffect((value: number) => value * 2); const onSourceFailed = jest.fn(); - effect.handle(throwError(new Error('test error')), { - onSourceFailed, - }); + effect.handle( + throwError(() => new Error('test error')), + { + onSourceFailed, + }, + ); expect(onSourceFailed).toBeCalledTimes(1); expect(onSourceFailed).toBeCalledWith(new Error('test error')); }); + it('should do nothing in case the event source throws an error and onSourceFailed callback is not provided', async () => { + const effect = createEffect((value: number) => value * 2); + + const finalPromise = firstValueFrom(effect.final$.pipe(timeout(10))); + + expect(() => + effect.handle(throwError(() => new Error('test error'))), + ).not.toThrowError(); + + await expect(finalPromise).rejects.toThrowError('Timeout has occurred'); + }); + it('should handle error from the source', async () => { const effect = createEffect((value: number) => value * 2);