Skip to content

Commit

Permalink
Add test for fromObservable
Browse files Browse the repository at this point in the history
  • Loading branch information
fboeller committed Mar 1, 2021
1 parent 63629a0 commit 50687b7
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 2 deletions.
152 changes: 152 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"codelyzer": "^6.0.0",
"husky": "^4.3.0",
"jest": "^26.6.3",
"jest-marbles": "^2.5.1",
"ng-packagr": "^11.1.2",
"ngx-build-plus": "^11.0.0",
"prettier": "^2.1.2",
Expand Down
19 changes: 17 additions & 2 deletions projects/ngx-loadable/src/lib/from.functions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fromPromise } from './from.functions';
import { errored, loaded } from './loadable.constructors';
import { fromObservable, fromPromise } from './from.functions';
import { errored, loaded, loading } from './loadable.constructors';
import { cold } from 'jest-marbles';

describe('the creation from a promise', () => {
it('returns a loaded result if the promise resolves', async () => {
Expand All @@ -14,3 +15,17 @@ describe('the creation from a promise', () => {
);
});
});

describe('the creation from an observable', () => {
it('returns first a loading state and then the loaded result if the observable does not error', () => {
expect(fromObservable(cold('(x|)', { x: 'value' }))).toBeObservable(
cold('(ab|)', { a: loading, b: loaded('value') })
);
});

it('returns first a loading state and then an error if the observable errors', () => {
expect(fromObservable(cold('#', {}, 'error'))).toBeObservable(
cold('(ab|)', { a: loading, b: errored('error') })
);
});
});

0 comments on commit 50687b7

Please sign in to comment.