Skip to content

Commit

Permalink
adopted tests to fit new implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed May 9, 2020
1 parent 0dcac87 commit 3fd9c3f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
48 changes: 19 additions & 29 deletions modules/component/spec/let/let.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ let letDirective: any;
template: `
<ng-container
*ngrxLet="value$ as value; $error as error; $complete as complete"
>{{ (value | json) || 'undefined' }}</ng-container
>{{
value === null ? 'null' : (value | json) || 'undefined'
}}</ng-container
>
`,
})
Expand Down Expand Up @@ -64,7 +66,6 @@ class LetDirectiveTestCompleteComponent {

let fixtureLetDirectiveTestComponent: any;
let letDirectiveTestComponent: {
strategy: any;
value$: Observable<any> | undefined | null;
};
let componentNativeElement: any;
Expand Down Expand Up @@ -231,22 +232,6 @@ describe('LetDirective', () => {
// Remains at 2, since that was the last value.
expect(componentNativeElement.textContent).toBe('2');
}));
});

describe('when error', () => {
beforeEach(async(setupLetDirectiveTestComponentError));

it('should render_creator the error to false if next or complete', () => {
letDirectiveTestComponent.value$ = of(1);
fixtureLetDirectiveTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe('false');
});

it('should render_creator the error to true if one occurs', () => {
letDirectiveTestComponent.value$ = throwError(new Error('error message'));
fixtureLetDirectiveTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe('true');
});

it('should render new value as value when a new observable was passed', () => {
letDirectiveTestComponent.value$ = of(42);
Expand All @@ -265,7 +250,7 @@ describe('LetDirective', () => {
it('should render values over time when a new observable was passed', fakeAsync(() => {
letDirectiveTestComponent.value$ = interval(1000).pipe(take(3));
fixtureLetDirectiveTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe('undefined');
expect(componentNativeElement.textContent).toBe('');
tick(1000);
fixtureLetDirectiveTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe('0');
Expand All @@ -283,24 +268,29 @@ describe('LetDirective', () => {
}));
});

describe('when complete', () => {
beforeEach(async(setupLetDirectiveTestComponentComplete));
describe('when error', () => {
beforeEach(async(setupLetDirectiveTestComponentError));

it('should render_creator true if completed', () => {
letDirectiveTestComponent.value$ = EMPTY;
it('should render_creator the error to false if next or complete', () => {
letDirectiveTestComponent.value$ = of(1);
fixtureLetDirectiveTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe('false');
});

it('should render_creator the error to true if one occurs', () => {
letDirectiveTestComponent.value$ = throwError(new Error('error message'));
fixtureLetDirectiveTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe('true');
});
});

describe('when using strategy', () => {
beforeEach(async(setupLetDirectiveTestComponentStrategy));
describe('when complete', () => {
beforeEach(async(setupLetDirectiveTestComponentComplete));

it('should work with different if a strategy other than the default', () => {
letDirectiveTestComponent.value$ = of(1, 2, 3, 4, 5);
letDirectiveTestComponent.strategy = 'local';
it('should render_creator true if completed', () => {
letDirectiveTestComponent.value$ = EMPTY;
fixtureLetDirectiveTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe('5');
expect(componentNativeElement.textContent).toBe('true');
});
});
});
3 changes: 0 additions & 3 deletions modules/component/src/core/cd-aware/cd-aware_creator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
EMPTY,
isObservable,
NextObserver,
Observable,
Subject,
Expand Down Expand Up @@ -61,8 +60,6 @@ export function createCdAware<U>(cfg: {
cfg.render();

return observable$.pipe(
// forward only observable values
filter(o$ => isObservable(o$)),
distinctUntilChanged(),
tap(cfg.updateViewContextObserver),
tap(() => cfg.render()),
Expand Down

0 comments on commit 3fd9c3f

Please sign in to comment.