Skip to content

Instantly share code, notes, and snippets.

@sebastienlevert
Created December 4, 2017 17:25
Show Gist options
  • Save sebastienlevert/d678b633888625a6e64fb2b147aa2419 to your computer and use it in GitHub Desktop.
Save sebastienlevert/d678b633888625a6e64fb2b147aa2419 to your computer and use it in GitHub Desktop.
//...}
@NgModule({
imports: [BrowserModule],
declarations: [MockData],
providers: [
{ provide: ListsService, useFactory: ListsServiceFactory }
],
entryComponents: [MockData]
})
export class MockDataModule {
ngDoBootstrap(){}
}
/**
* Lists Service Factory that provides the right service based on the context of the running WebPart
*/
export function ListsServiceFactory() {
if (Environment.type === EnvironmentType.Local) {
return new MockListsService();
} else if (Environment.type == EnvironmentType.SharePoint || Environment.type == EnvironmentType.ClassicSharePoint) {
return new ListsService();
}
};
@baywet
Copy link

baywet commented Jan 2, 2018

https://gist.github.com/sebastienlevert/d678b633888625a6e64fb2b147aa2419#file-mock-data-module-ts-L21 should be replaced by Environment.type === EnvironmentType.SharePoint || Environment.type === EnvironmentType.ClassicSharePoint to avoid lint errors

@baywet
Copy link

baywet commented Jan 2, 2018

https://gist.github.com/sebastienlevert/d678b633888625a6e64fb2b147aa2419#file-mock-data-module-ts-L19 should be replaced by if (Environment.type === EnvironmentType.Local || Environment.type === EnvironmentType.Test) { to cover all case and support unit tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment