4 |
--------------------------------------------------------------------------------
/apps/app1/src/app/feature3/feature3.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { Feature3Component } from './feature3.component';
4 |
5 | describe('Feature3Component', () => {
6 | let component: Feature3Component;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(
10 | async(() => {
11 | TestBed.configureTestingModule({
12 | declarations: [Feature3Component]
13 | }).compileComponents();
14 | })
15 | );
16 |
17 | beforeEach(() => {
18 | fixture = TestBed.createComponent(Feature3Component);
19 | component = fixture.componentInstance;
20 | fixture.detectChanges();
21 | });
22 |
23 | it('should create', () => {
24 | expect(component).toBeTruthy();
25 | });
26 | });
27 |
--------------------------------------------------------------------------------
/apps/app1/src/app/feature3/feature3.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-feature3',
5 | templateUrl: './feature3.component.html',
6 | styleUrls: ['./feature3.component.css']
7 | })
8 | export class Feature3Component implements OnInit {
9 | constructor() {}
10 |
11 | ngOnInit() {}
12 | }
13 |
--------------------------------------------------------------------------------
/apps/app1/src/app/feature3/feature3.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 | import { Feature3Component } from './feature3.component';
4 |
5 | @NgModule({
6 | imports: [CommonModule],
7 | declarations: [Feature3Component],
8 | exports: []
9 | })
10 | export class Feature3Module {}
11 |
--------------------------------------------------------------------------------
/apps/app1/src/app/services/index.ts:
--------------------------------------------------------------------------------
1 | import { SessionResolver } from '@nx-demo-jest/session-resolver';
2 |
3 | export * from '@nx-demo-jest/session-resolver';
4 |
5 | export const services: any[] = [SessionResolver];
6 |
--------------------------------------------------------------------------------
/apps/app1/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dereklin/nx-demo-jest/68c05805cc505596680337c4afce8b7c588a9f49/apps/app1/src/assets/.gitkeep
--------------------------------------------------------------------------------
/apps/app1/src/assets/nx-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dereklin/nx-demo-jest/68c05805cc505596680337c4afce8b7c588a9f49/apps/app1/src/assets/nx-logo.png
--------------------------------------------------------------------------------
/apps/app1/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true,
3 | httpServiceSettings: {
4 | endpoint: '/myprodendpoint',
5 | method: 'POST'
6 | }
7 | };
8 |
--------------------------------------------------------------------------------
/apps/app1/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // The file contents for the current environment will overwrite these during build.
2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do
3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead.
4 | // The list of which env maps to which file can be found in `.angular-cli.json`.
5 |
6 | export const environment = {
7 | production: false,
8 | httpServiceSettings: {
9 | endpoint: '/mydevendpoint',
10 | method: 'POST'
11 | }
12 | };
13 |
--------------------------------------------------------------------------------
/apps/app1/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dereklin/nx-demo-jest/68c05805cc505596680337c4afce8b7c588a9f49/apps/app1/src/favicon.ico
--------------------------------------------------------------------------------
/apps/app1/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | App1
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/apps/app1/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic()
12 | .bootstrapModule(AppModule)
13 | .catch(err => console.log(err));
14 |
--------------------------------------------------------------------------------
/apps/app1/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
38 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
39 |
40 | /** IE10 and IE11 requires the following for the Reflect API. */
41 | // import 'core-js/es6/reflect';
42 |
43 | /** Evergreen browsers require these. **/
44 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
45 | import 'core-js/es7/reflect';
46 |
47 | /**
48 | * Required to support Web Animations `@angular/platform-browser/animations`.
49 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
50 | **/
51 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
52 |
53 | /***************************************************************************************************
54 | * Zone JS is required by Angular itself.
55 | */
56 | import 'zone.js/dist/zone'; // Included with Angular CLI.
57 |
58 | /***************************************************************************************************
59 | * APPLICATION IMPORTS
60 | */
61 |
62 | /**
63 | * Date, currency, decimal and percent pipes.
64 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
65 | */
66 | // import 'intl'; // Run `npm install --save intl`.
67 | /**
68 | * Need to import at least one locale-data with intl.
69 | */
70 | // import 'intl/locale-data/jsonp/en';
71 |
--------------------------------------------------------------------------------
/apps/app1/src/styles.scss:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
--------------------------------------------------------------------------------
/apps/app1/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../../dist/out-tsc/apps/app1",
5 | "module": "es2015"
6 | },
7 | "include": [
8 | "**/*.ts"
9 | /* add all lazy-loaded libraries here: "../../../libs/my-lib/index.ts" */
10 |
11 | , "../../../libs/not-found/index.ts"
12 | ],
13 | "exclude": [
14 | "**/*.spec.ts"
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------
/apps/app2/e2e/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 |
3 | describe('app2 App', () => {
4 | let page: AppPage;
5 |
6 | beforeEach(() => {
7 | page = new AppPage();
8 | });
9 |
10 | it('should display welcome message', () => {
11 | page.navigateTo();
12 | expect(page.text()).toContain('Welcome');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/apps/app2/e2e/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo() {
5 | return browser.get('/');
6 | }
7 |
8 | text() {
9 | return browser.findElement(by.css('body')).getText();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/apps/app2/e2e/tsconfig.e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../../dist/out-tsc/e2e/app2",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | },
13 | "include": [
14 | "../**/*.ts"
15 | /* add all lazy-loaded libraries here: "../../../libs/my-lib/index.ts" */
16 | ],
17 | "exclude": [
18 | "**/*.spec.ts"
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/apps/app2/src/app/app.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dereklin/nx-demo-jest/68c05805cc505596680337c4afce8b7c588a9f49/apps/app2/src/app/app.component.css
--------------------------------------------------------------------------------
/apps/app2/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Welcome to an Angular CLI app built with Nrwl Nx!
5 |
6 |
7 |
8 |
9 |
Nx
10 |
11 | An open source toolkit for enterprise Angular applications.
12 |
13 | Nx is designed to help you create and build enterprise grade Angular applications. It provides an opinionated approach to application project structure and patterns.
14 |
15 |
Quick Start & Documentation
16 |
17 | Watch a 5-minute video on how to get started with Nx.
18 |
--------------------------------------------------------------------------------
/apps/app2/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { AppComponent } from './app.component';
4 | import { RouterTestingModule } from '@angular/router/testing';
5 |
6 | describe('AppComponent', () => {
7 | let component: AppComponent;
8 | let fixture: ComponentFixture;
9 |
10 | beforeEach(
11 | async(() => {
12 | TestBed.configureTestingModule({
13 | imports: [RouterTestingModule],
14 | declarations: [AppComponent]
15 | }).compileComponents();
16 | })
17 | );
18 |
19 | beforeEach(() => {
20 | fixture = TestBed.createComponent(AppComponent);
21 | component = fixture.componentInstance;
22 | fixture.detectChanges();
23 | });
24 |
25 | it('should create', () => {
26 | expect(component).toBeTruthy();
27 | });
28 | });
29 |
--------------------------------------------------------------------------------
/apps/app2/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-root',
5 | templateUrl: './app.component.html',
6 | styleUrls: ['./app.component.css']
7 | })
8 | export class AppComponent implements OnInit {
9 | constructor() {}
10 |
11 | ngOnInit() {}
12 | }
13 |
--------------------------------------------------------------------------------
/apps/app2/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { AppComponent } from './app.component';
3 | import { BrowserModule } from '@angular/platform-browser';
4 | import { NxModule } from '@nrwl/nx';
5 | import { RouterModule } from '@angular/router';
6 |
7 | @NgModule({
8 | imports: [BrowserModule, NxModule.forRoot(), RouterModule.forRoot([], { initialNavigation: 'enabled' })],
9 | declarations: [AppComponent],
10 | bootstrap: [AppComponent]
11 | })
12 | export class AppModule {}
13 |
--------------------------------------------------------------------------------
/apps/app2/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dereklin/nx-demo-jest/68c05805cc505596680337c4afce8b7c588a9f49/apps/app2/src/assets/.gitkeep
--------------------------------------------------------------------------------
/apps/app2/src/assets/nx-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dereklin/nx-demo-jest/68c05805cc505596680337c4afce8b7c588a9f49/apps/app2/src/assets/nx-logo.png
--------------------------------------------------------------------------------
/apps/app2/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/apps/app2/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // The file contents for the current environment will overwrite these during build.
2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do
3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead.
4 | // The list of which env maps to which file can be found in `.angular-cli.json`.
5 |
6 | export const environment = {
7 | production: false
8 | };
9 |
--------------------------------------------------------------------------------
/apps/app2/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dereklin/nx-demo-jest/68c05805cc505596680337c4afce8b7c588a9f49/apps/app2/src/favicon.ico
--------------------------------------------------------------------------------
/apps/app2/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | App2
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/apps/app2/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic()
12 | .bootstrapModule(AppModule)
13 | .catch(err => console.log(err));
14 |
--------------------------------------------------------------------------------
/apps/app2/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
38 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
39 |
40 | /** IE10 and IE11 requires the following for the Reflect API. */
41 | // import 'core-js/es6/reflect';
42 |
43 | /** Evergreen browsers require these. **/
44 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
45 | import 'core-js/es7/reflect';
46 |
47 | /**
48 | * Required to support Web Animations `@angular/platform-browser/animations`.
49 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
50 | **/
51 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
52 |
53 | /***************************************************************************************************
54 | * Zone JS is required by Angular itself.
55 | */
56 | import 'zone.js/dist/zone'; // Included with Angular CLI.
57 |
58 | /***************************************************************************************************
59 | * APPLICATION IMPORTS
60 | */
61 |
62 | /**
63 | * Date, currency, decimal and percent pipes.
64 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
65 | */
66 | // import 'intl'; // Run `npm install --save intl`.
67 | /**
68 | * Need to import at least one locale-data with intl.
69 | */
70 | // import 'intl/locale-data/jsonp/en';
71 |
--------------------------------------------------------------------------------
/apps/app2/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
--------------------------------------------------------------------------------
/apps/app2/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../../dist/out-tsc/apps/app2",
5 | "module": "es2015"
6 | },
7 | "include": [
8 | "**/*.ts"
9 | /* add all lazy-loaded libraries here: "../../../libs/my-lib/index.ts" */
10 | ],
11 | "exclude": [
12 | "**/*.spec.ts"
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/jest/jestGlobalMocks.ts:
--------------------------------------------------------------------------------
1 | const mock = () => {
2 | let storage = {};
3 | return {
4 | getItem: key => key in storage ? storage[key] : null,
5 | setItem: (key, value) => storage[key] = value || '',
6 | removeItem: key => delete storage[key],
7 | clear: () => storage = {},
8 | getStorage: () => storage
9 | };
10 | };
11 |
12 | Object.defineProperty(window, 'localStorage', {value: mock()});
13 | Object.defineProperty(global, 'localStorage', {value: mock()});
14 | Object.defineProperty(window, 'sessionStorage', {value: mock()});
15 | Object.defineProperty(global, 'sessionStorage', {value: mock()});
16 |
17 | Object.defineProperty(window, 'getComputedStyle', {
18 | value: () => ['-webkit-appearance']
19 | });
20 | Object.defineProperty(global, 'getComputedStyle', {
21 | value: () => ['-webkit-appearance']
22 | });
23 | Object.defineProperty(window, 'CSS', {value: mock()});
24 |
--------------------------------------------------------------------------------
/jest/setupJest.ts:
--------------------------------------------------------------------------------
1 | import 'jest-preset-angular';
2 | import './jestGlobalMocks';
3 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | const { makeSureNoAppIsSelected } = require('@nrwl/schematics/src/utils/cli-config-utils');
5 | // Nx only supports running unit tests for all apps and libs.
6 | makeSureNoAppIsSelected();
7 |
8 | module.exports = function (config) {
9 | config.set({
10 | basePath: '',
11 | frameworks: ['jasmine', '@angular/cli'],
12 | plugins: [
13 | require('karma-jasmine'),
14 | require('karma-chrome-launcher'),
15 | require('karma-jasmine-html-reporter'),
16 | require('karma-coverage-istanbul-reporter'),
17 | require('@angular/cli/plugins/karma')
18 | ],
19 | client:{
20 | clearContext: false // leave Jasmine Spec Runner output visible in browser
21 | },
22 | coverageIstanbulReporter: {
23 | reports: [ 'html', 'lcovonly' ],
24 | fixWebpackSourcePaths: true
25 | },
26 | angularCli: {
27 | environment: 'dev'
28 | },
29 | reporters: ['progress', 'kjhtml'],
30 | port: 9876,
31 | colors: true,
32 | logLevel: config.LOG_INFO,
33 | autoWatch: true,
34 | browsers: ['Chrome'],
35 | singleRun: false
36 | });
37 | };
38 |
--------------------------------------------------------------------------------
/libs/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dereklin/nx-demo-jest/68c05805cc505596680337c4afce8b7c588a9f49/libs/.gitkeep
--------------------------------------------------------------------------------
/libs/http-service/index.ts:
--------------------------------------------------------------------------------
1 | export { HttpServiceModule } from './src/http-service.module';
2 | export { HTTPSERVICE } from './src/http-service.tokens';
3 | export { HttpService } from './src/http-service';
4 | export { SimpleHttpService } from './src/simple-http.service';
5 | export { HttpClientService } from './src/http-client.service';
6 |
--------------------------------------------------------------------------------
/libs/http-service/src/http-client.service.spec.ts:
--------------------------------------------------------------------------------
1 | import { HttpClientModule } from '@angular/common/http';
2 | import { TestBed, inject } from '@angular/core/testing';
3 |
4 | import { HttpClientService } from './http-client.service';
5 |
6 | describe('HttpClientService', () => {
7 | beforeEach(() => {
8 | TestBed.configureTestingModule({
9 | providers: [HttpClientService],
10 | imports: [HttpClientModule]
11 | });
12 | });
13 |
14 | it(
15 | 'should be created',
16 | inject([HttpClientService], (service: HttpClientService) => {
17 | expect(service).toBeTruthy();
18 | })
19 | );
20 | });
21 |
--------------------------------------------------------------------------------
/libs/http-service/src/http-client.service.ts:
--------------------------------------------------------------------------------
1 | // This code is not tested and might cause errors
2 | import { HttpClient, HttpHeaders } from '@angular/common/http';
3 | import { Injectable } from '@angular/core';
4 | import { Response } from '@angular/http';
5 | import { Observable } from 'rxjs/Observable';
6 | import { of } from 'rxjs/observable/of';
7 | import { catchError, map } from 'rxjs/operators';
8 |
9 | @Injectable()
10 | export class HttpClientService {
11 | private headers: HttpHeaders;
12 |
13 | constructor(private http: HttpClient) {
14 | this.headers = new HttpHeaders({ 'Content-Type': 'application/json', Accept: 'application/json' });
15 | this.headers.append('Cache-control', 'no-cache');
16 | this.headers.append('Cache-control', 'no-store');
17 | this.headers.append('Expires', '0');
18 | this.headers.append('Pragma', 'no-cache');
19 | }
20 |
21 | public post(url, data): Observable {
22 | return this.http
23 | .post(url, data, { headers: this.headers })
24 | .pipe(map(this.extractData), catchError(this.handleError));
25 | }
26 |
27 | private extractData(res: Response) {
28 | return res;
29 | }
30 |
31 | private handleError(error: Response | any) {
32 | let errMsg: string;
33 | if (error instanceof Response) {
34 | try {
35 | errMsg = `${error.status} - ${error.statusText || ''}`;
36 | const body = error.json() || '';
37 | const err = body.error || JSON.stringify(body);
38 | errMsg = `${errMsg} ${err}`;
39 | } catch (e2) {
40 | if (error['_body']) {
41 | errMsg = `${errMsg} ${error['_body']}`;
42 | }
43 | }
44 | } else {
45 | errMsg = error ? (error.message ? error.message : error.toString()) : '';
46 | }
47 | console.error(errMsg);
48 | return of(undefined);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/libs/http-service/src/http-service.module.spec.ts:
--------------------------------------------------------------------------------
1 | import { HttpServiceModule } from './http-service.module';
2 |
3 | describe('HttpServiceModule', () => {
4 | it('should work', () => {
5 | expect(new HttpServiceModule()).toBeDefined();
6 | });
7 | });
8 |
--------------------------------------------------------------------------------
/libs/http-service/src/http-service.module.ts:
--------------------------------------------------------------------------------
1 | import { HttpClientModule } from '@angular/common/http';
2 | import { HttpClientService } from './http-client.service';
3 | import { SimpleHttpService } from './simple-http.service';
4 | import { HTTPSERVICE, HTTPSERVICESETTINGS } from './http-service.tokens';
5 | import { ModuleWithProviders, NgModule } from '@angular/core';
6 | import { CommonModule } from '@angular/common';
7 |
8 | @NgModule({
9 | imports: [CommonModule, HttpClientModule]
10 | })
11 | export class HttpServiceModule {
12 | public static register({httpServiceSettings}): ModuleWithProviders {
13 | return {
14 | ngModule: HttpServiceModule,
15 | providers: [
16 | { provide: HTTPSERVICESETTINGS, useValue: httpServiceSettings },
17 | { provide: HTTPSERVICE, useClass: SimpleHttpService },
18 | HttpClientService
19 | ]
20 | };
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/libs/http-service/src/http-service.tokens.ts:
--------------------------------------------------------------------------------
1 | import { InjectionToken } from '@angular/core';
2 |
3 | export const HTTPSERVICE = new InjectionToken('http-service');
4 | export const HTTPSERVICESETTINGS = new InjectionToken('http-service-settings');
5 |
--------------------------------------------------------------------------------
/libs/http-service/src/http-service.ts:
--------------------------------------------------------------------------------
1 | import { Observable } from 'rxjs/Observable';
2 |
3 | export interface HttpService {
4 | post(service: string, method: string, request: any): Observable;
5 | }
6 |
--------------------------------------------------------------------------------
/libs/http-service/src/simple-http.service.spec.ts:
--------------------------------------------------------------------------------
1 | import { HTTPSERVICESETTINGS } from './http-service.tokens';
2 | import { HttpClientService } from './http-client.service';
3 | import { HttpClientModule } from '@angular/common/http';
4 | import { TestBed, inject } from '@angular/core/testing';
5 |
6 | import { SimpleHttpService } from './simple-http.service';
7 |
8 | describe('SimpleHttpServiceService', () => {
9 | beforeEach(() => {
10 | TestBed.configureTestingModule({
11 | providers: [
12 | SimpleHttpService,
13 | HttpClientService,
14 | { provide: HTTPSERVICESETTINGS, useValue: {} }
15 | ],
16 | imports: [HttpClientModule]
17 | });
18 | });
19 |
20 | it(
21 | 'should be created',
22 | inject([SimpleHttpService], (service: SimpleHttpService) => {
23 | expect(service).toBeTruthy();
24 | })
25 | );
26 | });
27 |
--------------------------------------------------------------------------------
/libs/http-service/src/simple-http.service.ts:
--------------------------------------------------------------------------------
1 | import { HTTPSERVICESETTINGS } from './http-service.tokens';
2 | import { HttpService } from './http-service';
3 | import { Inject, Injectable } from '@angular/core';
4 | import { Observable } from 'rxjs/Observable';
5 | import { empty } from 'rxjs/observable/empty';
6 |
7 | import { HttpClientService } from './http-client.service';
8 | import { map, catchError } from 'rxjs/operators';
9 | import { of } from 'rxjs/observable/of';
10 |
11 | @Injectable()
12 | export class SimpleHttpService implements HttpService {
13 | constructor(
14 | private httpClientService: HttpClientService,
15 | @Inject(HTTPSERVICESETTINGS) private httpServiceSettings: any
16 | ) {}
17 |
18 | /**
19 | * Construct a complete url and post request
20 | * @param service
21 | * @param method
22 | * @param request
23 | * @returns {Observable}
24 | */
25 | public post(service: string, method: string, request: any): Observable {
26 | console.log('httpServiceSettings', this.httpServiceSettings);
27 | return of({ name: 'test' });
28 | }
29 |
30 | private paramaterizeJson(data) {
31 | return Object.keys(data)
32 | .map(k => {
33 | let value = data[k];
34 | if (typeof value === 'object') {
35 | value = JSON.stringify(value);
36 | }
37 | return encodeURIComponent(k) + '=' + encodeURIComponent(value);
38 | })
39 | .join('&');
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/libs/not-found/index.ts:
--------------------------------------------------------------------------------
1 | export { NotFoundModule } from './src/not-found.module';
2 | export { NotFoundComponent } from './src/not-found/not-found.component';
3 |
--------------------------------------------------------------------------------
/libs/not-found/src/not-found.module.spec.ts:
--------------------------------------------------------------------------------
1 | import { NotFoundModule } from './not-found.module';
2 |
3 | describe('NotFoundModule', () => {
4 | it('should work', () => {
5 | expect(new NotFoundModule()).toBeDefined();
6 | });
7 | });
8 |
--------------------------------------------------------------------------------
/libs/not-found/src/not-found.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 | import { RouterModule } from '@angular/router';
4 | import { NotFoundComponent } from './not-found/not-found.component';
5 |
6 | @NgModule({
7 | imports: [CommonModule, RouterModule.forChild([{ path: '', component: NotFoundComponent }])],
8 | declarations: [NotFoundComponent]
9 | })
10 | export class NotFoundModule {}
11 |
--------------------------------------------------------------------------------
/libs/not-found/src/not-found/not-found.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dereklin/nx-demo-jest/68c05805cc505596680337c4afce8b7c588a9f49/libs/not-found/src/not-found/not-found.component.css
--------------------------------------------------------------------------------
/libs/not-found/src/not-found/not-found.component.html:
--------------------------------------------------------------------------------
1 |