Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Testing Module #265

Open
wants to merge 1 commit into
base: v2.1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/ngx-jsonapi-testing.module.ts
Original file line number Diff line number Diff line change
@@ -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 }]
};
}
}