From d83c4c2a46c8183857928e5d3ab3066c8f3f1586 Mon Sep 17 00:00:00 2001 From: Zhang Haochuan Jack Date: Thu, 12 Mar 2020 15:50:45 +0800 Subject: [PATCH] testing module --- src/ngx-jsonapi-testing.module.ts | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/ngx-jsonapi-testing.module.ts diff --git a/src/ngx-jsonapi-testing.module.ts b/src/ngx-jsonapi-testing.module.ts new file mode 100644 index 00000000..10524109 --- /dev/null +++ b/src/ngx-jsonapi-testing.module.ts @@ -0,0 +1,38 @@ +import { NgModule, ModuleWithProviders, Optional, SkipSelf } from '@angular/core'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; + +import { Core as JsonapiCore } from './core'; +import { Http as JsonapiHttp } from './sources/http.service'; +import { StoreService as JsonapiStore } from './sources/store.service'; + +// testing +import { JsonapiConfig } from './jsonapi-config'; + +@NgModule({ + exports: [ + HttpClientTestingModule + ], + providers: [ + JsonapiCore, + JsonapiStore, + JsonapiConfig, // Need this here for testing + JsonapiHttp + ] +}) +export class NgxJsonapiTestingModule { + public constructor( + @Optional() + @SkipSelf() + parentModule: NgxJsonapiTestingModule ) { + if (parentModule) { + throw new Error('NgxJsonapiTestingModule is already loaded. Import it in the AppModule only'); + } + } + + public static forRoot(config: JsonapiConfig): ModuleWithProviders { + return { + ngModule: NgxJsonapiTestingModule, + providers: [{ provide: JsonapiConfig, useValue: config }] + }; + } +}