Skip to content

Commit

Permalink
Add test for custom global error state
Browse files Browse the repository at this point in the history
  • Loading branch information
fboeller committed Mar 7, 2021
1 parent 5ca41e5 commit d785053
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, NgModule } from '@angular/core';
import { Component, Input, NgModule } from '@angular/core';
import { loading } from '../../loadable.constructors';

@Component({
Expand All @@ -14,3 +14,18 @@ export class TestLoadingSpinnerComponent {
entryComponents: [TestLoadingSpinnerComponent],
})
export class TestLoadingSpinnerModule {}

@Component({
selector: 'ld-test-error',
template: `<span>Error {{ error }}</span>`,
})
export class TestErrorFixtureComponent {
@Input() error: any;
loadable = loading;
}

@NgModule({
declarations: [TestErrorFixtureComponent],
entryComponents: [TestErrorFixtureComponent],
})
export class TestErrorModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { By } from '@angular/platform-browser';
import { errored, idle, loaded, loading } from '../../loadable.constructors';
import { LoadableModule } from '../loadable.module';
import {
TestErrorFixtureComponent,
TestErrorModule,
TestLoadingSpinnerComponent,
TestLoadingSpinnerModule,
} from './loadable.component.fixtures';
Expand Down Expand Up @@ -140,3 +142,40 @@ it('renders the custom global loading state if loading', fakeAsync(() => {
).toBeTruthy();
expect(fixture.debugElement.query(By.css('p'))).toBeFalsy();
}));

@Component({
selector: 'ld-test-default-loading',
template: `
<ld-loadable [loadable]="loadable">
<p>{{ loadable | loadedValue }}</p>
</ld-loadable>
`,
})
class TestDefaultErrorComponent {
loadable = errored('error');
}

it('renders the custom global error state if errored', fakeAsync(() => {
TestBed.configureTestingModule({
declarations: [TestDefaultErrorComponent],
imports: [
TestErrorModule,
LoadableModule.forRoot({
defaultComponents: {
error: TestErrorFixtureComponent,
},
}),
],
});
const fixture = TestBed.createComponent(TestDefaultErrorComponent);
fixture.detectChanges();
tick(1);
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('ld-loadable-error'))).toBeFalsy();
expect(fixture.debugElement.query(By.css('ld-test-error'))).toBeTruthy();
expect(
fixture.debugElement.query(By.css('ld-test-error span')).nativeElement
.textContent
).toEqual('Error error');
expect(fixture.debugElement.query(By.css('p'))).toBeFalsy();
}));

0 comments on commit d785053

Please sign in to comment.