fix all testing problems

pull/9837/head
mehmet-erim 4 years ago
parent 47eddc660f
commit 696333726c

@ -228,6 +228,7 @@
},
"configurations": {
"production": {
"tsConfig": "apps/dev-app/tsconfig.prod.json",
"budgets": [
{
"type": "initial",

@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.prod.json",
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": [],
"paths": {}
},
"angularCompilerOptions": {
"enableIvy": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
},
"files": ["src/main.ts", "src/polyfills.ts"],
"include": ["src/**/*.ts"],
"exclude": ["src/test.ts", "src/**/*.spec.ts", "src/environments/*.ts"]
}

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -7,7 +7,9 @@
"nx": "nx",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"build:all": "nx run-many --target=build --all --exclude=dev-app,schematics",
"test": "ng test --detect-open-handles=true --run-in-band=true --watch-all=true",
"test:all": "nx run-many --target=test --all",
"lint": "nx workspace-lint && ng lint",
"e2e": "ng e2e",
"affected:apps": "nx affected:apps",
@ -25,7 +27,6 @@
"workspace-generator": "nx workspace-generator",
"dep-graph": "nx dep-graph",
"help": "nx help",
"build-all-packages": "nx run-many --target=build --all --exclude=dev-app,schematics",
"compile:ivy": "yarn ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points --tsconfig './tsconfig.prod.json' --source node_modules",
"postinstall": "node ./decorate-angular-cli.js && yarn compile:ivy"
},

@ -1,16 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { AuthWrapperService } from './auth-wrapper.service';
describe('AuthWrapperService', () => {
let service: AuthWrapperService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(AuthWrapperService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

@ -1,16 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { TenantBoxService } from './tenant-box.service';
describe('TenantBoxService', () => {
let service: TenantBoxService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TenantBoxService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -1,11 +1,12 @@
import { CoreTestingModule } from '@abp/ng.core/testing';
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { ApplicationConfiguration } from '../models/application-configuration';
import { Store } from '@ngxs/store';
import {
ApplicationConfigurationDto,
CurrentUserDto,
} from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/models';
import { ConfigStateService } from '../services';
import { CoreTestingModule } from '@abp/ng.core/testing';
import { CORE_OPTIONS } from '../tokens';
export const CONFIG_STATE_DATA = {
environment: {
@ -107,6 +108,10 @@ describe('ConfigState', () => {
const createService = createServiceFactory({
service: ConfigStateService,
imports: [CoreTestingModule.withConfig()],
providers: [
{ provide: CORE_OPTIONS, useValue: { skipGetAppConfiguration: true } },
{ provide: Store, useValue: {} },
],
});
beforeEach(() => {
@ -119,29 +124,35 @@ describe('ConfigState', () => {
describe('#getAll', () => {
it('should return CONFIG_STATE_DATA', () => {
expect(configState.getAll()).toEqual(CONFIG_STATE_DATA);
configState.getAll$().subscribe(data => expect(data).toEqual(CONFIG_STATE_DATA));
configState
.getAll$()
.subscribe((data) => expect(data).toEqual(CONFIG_STATE_DATA));
});
});
describe('#getOne', () => {
it('should return one property', () => {
expect(configState.getOne('localization')).toEqual(CONFIG_STATE_DATA.localization);
expect(configState.getOne('localization')).toEqual(
CONFIG_STATE_DATA.localization
);
configState
.getOne$('localization')
.subscribe(localization => expect(localization).toEqual(CONFIG_STATE_DATA.localization));
.subscribe((localization) =>
expect(localization).toEqual(CONFIG_STATE_DATA.localization)
);
});
});
describe('#getDeep', () => {
it('should return deeper', () => {
expect(configState.getDeep('localization.languages')).toEqual(
CONFIG_STATE_DATA.localization.languages,
CONFIG_STATE_DATA.localization.languages
);
configState
.getDeep$('localization.languages')
.subscribe(languages =>
expect(languages).toEqual(CONFIG_STATE_DATA.localization.languages),
.subscribe((languages) =>
expect(languages).toEqual(CONFIG_STATE_DATA.localization.languages)
);
expect(configState.getDeep('test')).toBeFalsy();
@ -151,22 +162,30 @@ describe('ConfigState', () => {
describe('#getFeature', () => {
it('should return a setting', () => {
expect(configState.getFeature('Chat.Enable')).toEqual(
CONFIG_STATE_DATA.features.values['Chat.Enable'],
CONFIG_STATE_DATA.features.values['Chat.Enable']
);
configState
.getFeature$('Chat.Enable')
.subscribe(data => expect(data).toEqual(CONFIG_STATE_DATA.features.values['Chat.Enable']));
.subscribe((data) =>
expect(data).toEqual(CONFIG_STATE_DATA.features.values['Chat.Enable'])
);
});
});
describe('#getSetting', () => {
it('should return a setting', () => {
expect(configState.getSetting('Abp.Localization.DefaultLanguage')).toEqual(
CONFIG_STATE_DATA.setting.values['Abp.Localization.DefaultLanguage'],
expect(
configState.getSetting('Abp.Localization.DefaultLanguage')
).toEqual(
CONFIG_STATE_DATA.setting.values['Abp.Localization.DefaultLanguage']
);
configState.getSetting$('Abp.Localization.DefaultLanguage').subscribe(data => {
expect(data).toEqual(CONFIG_STATE_DATA.setting.values['Abp.Localization.DefaultLanguage']);
});
configState
.getSetting$('Abp.Localization.DefaultLanguage')
.subscribe((data) => {
expect(data).toEqual(
CONFIG_STATE_DATA.setting.values['Abp.Localization.DefaultLanguage']
);
});
});
});
@ -177,9 +196,14 @@ describe('ConfigState', () => {
${'Localization'} | ${{ 'Abp.Localization.DefaultLanguage': 'en' }}
${'X'} | ${{}}
${'localization'} | ${{}}
`('should return $expected when keyword is given as $keyword', ({ keyword, expected }) => {
expect(configState.getSettings(keyword)).toEqual(expected);
configState.getSettings$(keyword).subscribe(data => expect(data).toEqual(expected));
});
`(
'should return $expected when keyword is given as $keyword',
({ keyword, expected }) => {
expect(configState.getSettings(keyword)).toEqual(expected);
configState
.getSettings$(keyword)
.subscribe((data) => expect(data).toEqual(expected));
}
);
});
});

@ -17,13 +17,17 @@ const mockInitialState = {
type MockState = typeof mockInitialState;
const deepPatch1: DeepPartial<MockState> = { foo: { bar: { baz: [() => {}] } } };
const deepPatch1: DeepPartial<MockState> = {
foo: { bar: { baz: [() => {}] } },
};
const deepPatchExpected1: MockState = clone(mockInitialState);
deepPatchExpected1.foo.bar.baz = deepPatch1.foo.bar.baz;
const deepPatch2: DeepPartial<MockState> = { foo: { bar: { qux: Promise.resolve() } } };
const deepPatch2: DeepPartial<MockState> = {
foo: { bar: { qux: Promise.resolve() } },
};
const deepPatchExpected2: MockState = clone(mockInitialState);
deepPatchExpected2.foo.bar.qux = deepPatch2.foo.bar.qux;
deepPatchExpected2.foo.bar.qux = deepPatch2.foo.bar.qux as any;
const deepPatch3: DeepPartial<MockState> = { foo: { n: 1 } };
const deepPatchExpected3: MockState = clone(mockInitialState);
@ -49,7 +53,9 @@ const patch2: Partial<MockState> = {
const patchExpected2: MockState = clone(mockInitialState);
patchExpected2.foo = patch2.foo;
const patch3: Partial<MockState> = { foo: { n: 1 } as typeof mockInitialState.foo };
const patch3: Partial<MockState> = {
foo: { n: 1 } as typeof mockInitialState.foo,
};
const patchExpected3: MockState = clone(mockInitialState);
patchExpected3.foo = patch3.foo;
@ -76,10 +82,13 @@ describe('Internal Store', () => {
async ({ selector, expected }) => {
const store = new InternalStore(mockInitialState);
const value = await store.sliceState(selector).pipe(take(1)).toPromise();
const value = await store
.sliceState(selector)
.pipe(take(1))
.toPromise();
expect(value).toEqual(expected);
},
}
);
});
@ -91,13 +100,16 @@ describe('Internal Store', () => {
${deepPatch3} | ${deepPatchExpected3}
${deepPatch4} | ${deepPatchExpected4}
${deepPatch5} | ${deepPatchExpected5}
`('should set state as $expected when patch is $patch', ({ patch, expected }) => {
const store = new InternalStore(mockInitialState);
`(
'should set state as $expected when patch is $patch',
({ patch, expected }) => {
const store = new InternalStore(mockInitialState);
store.deepPatch(patch);
store.deepPatch(patch);
expect(store.state).toEqual(expected);
});
expect(store.state).toEqual(expected);
}
);
});
describe('patchState', () => {
@ -108,22 +120,25 @@ describe('Internal Store', () => {
${patch3} | ${patchExpected3}
${patch4} | ${patchExpected4}
${patch5} | ${patchExpected5}
`('should set state as $expected when patch is $patch', ({ patch, expected }) => {
const store = new InternalStore(mockInitialState);
`(
'should set state as $expected when patch is $patch',
({ patch, expected }) => {
const store = new InternalStore(mockInitialState);
store.patch(patch);
store.patch(patch);
expect(store.state).toEqual(expected);
});
expect(store.state).toEqual(expected);
}
);
});
describe('sliceUpdate', () => {
it('should return slice of update$ based on selector', done => {
it('should return slice of update$ based on selector', (done) => {
const store = new InternalStore(mockInitialState);
const onQux$ = store.sliceUpdate(state => state.foo.bar.qux);
const onQux$ = store.sliceUpdate((state) => state.foo.bar.qux);
onQux$.pipe(take(1)).subscribe(value => {
onQux$.pipe(take(1)).subscribe((value) => {
expect(value).toEqual(deepPatch2.foo.bar.qux);
done();
});

@ -1,13 +1,19 @@
import { CoreTestingModule } from '@abp/ng.core/testing';
import { APP_BASE_HREF } from '@angular/common';
import { Component } from '@angular/core';
import { RouterModule } from '@angular/router';
import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest';
import {
createServiceFactory,
SpectatorService,
SpyObject,
} from '@ngneat/spectator/jest';
import { Actions, Store } from '@ngxs/store';
import { of } from 'rxjs';
import { RestOccurError } from '../actions';
import { PermissionGuard } from '../guards/permission.guard';
import { RoutesService } from '../services/routes.service';
import { PermissionService } from '../services';
import { RoutesService } from '../services/routes.service';
import { CORE_OPTIONS } from '../tokens';
describe('PermissionGuard', () => {
let spectator: SpectatorService<PermissionGuard>;
@ -24,15 +30,19 @@ describe('PermissionGuard', () => {
mocks: [PermissionService, Store],
declarations: [DummyComponent],
imports: [
RouterModule.forRoot([
{
path: 'test',
component: DummyComponent,
data: {
requiredPolicy: 'TestPolicy',
},
},
], { relativeLinkResolution: 'legacy' }),
CoreTestingModule.withConfig(),
RouterModule.forRoot(
[
{
path: 'test',
component: DummyComponent,
data: {
requiredPolicy: 'TestPolicy',
},
},
],
{ relativeLinkResolution: 'legacy' }
),
],
providers: [
{
@ -47,6 +57,7 @@ describe('PermissionGuard', () => {
},
},
},
{ provide: CORE_OPTIONS, useValue: { skipGetAppConfiguration: true } },
],
});
@ -58,28 +69,34 @@ describe('PermissionGuard', () => {
permissionService = spectator.inject(PermissionService);
});
it('should return true when the grantedPolicy is true', done => {
it('should return true when the grantedPolicy is true', (done) => {
permissionService.getGrantedPolicy$.andReturn(of(true));
const spy = jest.spyOn(store, 'dispatch');
guard.canActivate({ data: { requiredPolicy: 'test' } } as any, null).subscribe(res => {
expect(res).toBe(true);
expect(spy.mock.calls).toHaveLength(0);
done();
});
guard
.canActivate({ data: { requiredPolicy: 'test' } } as any, null)
.subscribe((res) => {
expect(res).toBe(true);
expect(spy.mock.calls).toHaveLength(0);
done();
});
});
it('should return false and dispatch RestOccurError when the grantedPolicy is false', done => {
it('should return false and dispatch RestOccurError when the grantedPolicy is false', (done) => {
permissionService.getGrantedPolicy$.andReturn(of(false));
const spy = jest.spyOn(store, 'dispatch');
guard.canActivate({ data: { requiredPolicy: 'test' } } as any, null).subscribe(res => {
expect(res).toBe(false);
expect(spy.mock.calls[0][0] instanceof RestOccurError).toBeTruthy();
expect((spy.mock.calls[0][0] as RestOccurError).payload).toEqual({ status: 403 });
done();
});
guard
.canActivate({ data: { requiredPolicy: 'test' } } as any, null)
.subscribe((res) => {
expect(res).toBe(false);
expect(spy.mock.calls[0][0] instanceof RestOccurError).toBeTruthy();
expect((spy.mock.calls[0][0] as RestOccurError).payload).toEqual({
status: 403,
});
done();
});
});
it('should check the requiredPolicy from RoutesService', done => {
it('should check the requiredPolicy from RoutesService', (done) => {
routes.add([
{
path: '/test',
@ -87,23 +104,29 @@ describe('PermissionGuard', () => {
requiredPolicy: 'TestPolicy',
},
]);
permissionService.getGrantedPolicy$.mockImplementation(policy => of(policy === 'TestPolicy'));
guard.canActivate({ data: {} } as any, { url: 'test' } as any).subscribe(result => {
expect(result).toBe(true);
done();
});
permissionService.getGrantedPolicy$.mockImplementation((policy) =>
of(policy === 'TestPolicy')
);
guard
.canActivate({ data: {} } as any, { url: 'test' } as any)
.subscribe((result) => {
expect(result).toBe(true);
done();
});
});
it('should return Observable<true> if RoutesService does not have requiredPolicy for given URL', done => {
it('should return Observable<true> if RoutesService does not have requiredPolicy for given URL', (done) => {
routes.add([
{
path: '/test',
name: 'Test',
},
]);
guard.canActivate({ data: {} } as any, { url: 'test' } as any).subscribe(result => {
expect(result).toBe(true);
done();
});
guard
.canActivate({ data: {} } as any, { url: 'test' } as any)
.subscribe((result) => {
expect(result).toBe(true);
done();
});
});
});

@ -1,4 +1,9 @@
import { createHttpFactory, HttpMethod, SpectatorHttp, SpyObject } from '@ngneat/spectator/jest';
import {
createHttpFactory,
HttpMethod,
SpectatorHttp,
SpyObject,
} from '@ngneat/spectator/jest';
import { Store } from '@ngxs/store';
import { EnvironmentService, ProfileService, RestService } from '../services';
import { CORE_OPTIONS } from '../tokens';
@ -8,7 +13,7 @@ describe('ProfileService', () => {
let environmentService: SpyObject<EnvironmentService>;
const createHttp = createHttpFactory({
dataService: ProfileService,
service: ProfileService,
providers: [
RestService,
{ provide: CORE_OPTIONS, useValue: {} },
@ -26,7 +31,10 @@ describe('ProfileService', () => {
it('should send a GET to my-profile API', () => {
spectator.service.get().subscribe();
spectator.expectOne('https://abp.io/api/identity/my-profile', HttpMethod.GET);
spectator.expectOne(
'https://abp.io/api/identity/my-profile',
HttpMethod.GET
);
});
it('should send a POST to change-password API', () => {
@ -34,7 +42,7 @@ describe('ProfileService', () => {
spectator.service.changePassword(mock).subscribe();
const req = spectator.expectOne(
'https://abp.io/api/identity/my-profile/change-password',
HttpMethod.POST,
HttpMethod.POST
);
expect(req.request.body).toEqual(mock);
});
@ -50,7 +58,10 @@ describe('ProfileService', () => {
hasPassword: false,
};
spectator.service.update(mock).subscribe();
const req = spectator.expectOne('https://abp.io/api/identity/my-profile', HttpMethod.PUT);
const req = spectator.expectOne(
'https://abp.io/api/identity/my-profile',
HttpMethod.PUT
);
expect(req.request.body).toEqual(mock);
});
});

@ -46,7 +46,9 @@ describe('ComponentProjectionStrategy', () => {
beforeEach(() => {
spectator = createComponent({});
containerStrategy = CONTAINER_STRATEGY.Clear(spectator.component.containerRef);
containerStrategy = CONTAINER_STRATEGY.Clear(
spectator.component.containerRef
);
});
afterEach(() => {
@ -56,8 +58,11 @@ describe('ComponentProjectionStrategy', () => {
describe('#injectContent', () => {
it('should should insert content into container and return a ComponentRef', () => {
const strategy = new ComponentProjectionStrategy(TestComponent, containerStrategy);
componentRef = strategy.injectContent(spectator);
const strategy = new ComponentProjectionStrategy(
TestComponent,
containerStrategy
);
componentRef = strategy.injectContent({ get: spectator.inject });
spectator.detectChanges();
const div = spectator.query('div.foo');
@ -70,9 +75,9 @@ describe('ComponentProjectionStrategy', () => {
const strategy = new ComponentProjectionStrategy(
TestComponent,
containerStrategy,
contextStrategy,
contextStrategy
);
componentRef = strategy.injectContent(spectator);
componentRef = strategy.injectContent({ get: spectator.inject });
spectator.detectChanges();
const div = spectator.query('div.foo');
@ -114,7 +119,7 @@ describe('RootComponentProjectionStrategy', () => {
describe('#injectContent', () => {
it('should should insert content into body and return a ComponentRef', () => {
const strategy = new RootComponentProjectionStrategy(TestComponent);
componentRef = strategy.injectContent(spectator);
componentRef = strategy.injectContent({ get: spectator.inject });
spectator.detectChanges();
const div = document.querySelector('body > ng-component > div.foo');
@ -126,8 +131,11 @@ describe('RootComponentProjectionStrategy', () => {
it('should be able to map context to projected component', () => {
const contextStrategy = CONTEXT_STRATEGY.Component({ bar: 'bar' });
const strategy = new RootComponentProjectionStrategy(TestComponent, contextStrategy);
componentRef = strategy.injectContent(spectator);
const strategy = new RootComponentProjectionStrategy(
TestComponent,
contextStrategy
);
componentRef = strategy.injectContent({ get: spectator.inject });
spectator.detectChanges();
const div = document.querySelector('body > ng-component > div.foo');
@ -166,7 +174,9 @@ describe('TemplateProjectionStrategy', () => {
beforeEach(() => {
spectator = createComponent({});
containerStrategy = CONTAINER_STRATEGY.Clear(spectator.component.containerRef);
containerStrategy = CONTAINER_STRATEGY.Clear(
spectator.component.containerRef
);
});
afterEach(() => {
@ -177,7 +187,10 @@ describe('TemplateProjectionStrategy', () => {
describe('#injectContent', () => {
it('should should insert content into container and return an EmbeddedViewRef', () => {
const templateRef = spectator.component.templateRef;
const strategy = new TemplateProjectionStrategy(templateRef, containerStrategy);
const strategy = new TemplateProjectionStrategy(
templateRef,
containerStrategy
);
embeddedViewRef = strategy.injectContent();
spectator.detectChanges();
@ -194,11 +207,13 @@ describe('TemplateProjectionStrategy', () => {
it('should be able to map context to projected template', () => {
const templateRef = spectator.component.templateRef;
const contextStrategy = CONTEXT_STRATEGY.Template<typeof templateRef>({ $implicit: 'bar' });
const contextStrategy = CONTEXT_STRATEGY.Template<typeof templateRef>({
$implicit: 'bar',
});
const strategy = new TemplateProjectionStrategy(
templateRef,
containerStrategy,
contextStrategy,
contextStrategy
);
embeddedViewRef = strategy.injectContent();
spectator.detectChanges();
@ -212,7 +227,7 @@ describe('TemplateProjectionStrategy', () => {
describe('PROJECTION_STRATEGY', () => {
const content = undefined;
const containerRef = ({ length: 0 } as any) as ViewContainerRef;
const containerRef = { length: 0 } as any as ViewContainerRef;
let context: any;
test.each`
@ -227,9 +242,13 @@ describe('PROJECTION_STRATEGY', () => {
'should successfully map $name to $Strategy.name with $containerStrategy.name container strategy and $contextStrategy.name context strategy',
({ name, Strategy, containerStrategy }) => {
expect(PROJECTION_STRATEGY[name](content, containerRef, context)).toEqual(
new Strategy(content, containerStrategy(containerRef), CONTEXT_STRATEGY.None()),
new Strategy(
content,
containerStrategy(containerRef),
CONTEXT_STRATEGY.None()
)
);
},
}
);
test.each`
name | Strategy | domStrategy
@ -238,9 +257,9 @@ describe('PROJECTION_STRATEGY', () => {
'should successfully map $name to $Strategy.name with $domStrategy.name dom strategy',
({ name, Strategy, domStrategy }) => {
expect(PROJECTION_STRATEGY[name](content, context)).toEqual(
new Strategy(content, CONTEXT_STRATEGY.None(), domStrategy()),
new Strategy(content, CONTEXT_STRATEGY.None(), domStrategy())
);
},
}
);
test.each`
@ -256,9 +275,13 @@ describe('PROJECTION_STRATEGY', () => {
({ name, Strategy, containerStrategy, contextStrategy }) => {
context = { x: true };
expect(PROJECTION_STRATEGY[name](content, containerRef, context)).toEqual(
new Strategy(content, containerStrategy(containerRef), contextStrategy(context)),
new Strategy(
content,
containerStrategy(containerRef),
contextStrategy(context)
)
);
},
}
);
test.each`
@ -269,8 +292,8 @@ describe('PROJECTION_STRATEGY', () => {
({ name, Strategy, domStrategy, contextStrategy }) => {
context = { x: true };
expect(PROJECTION_STRATEGY[name](content, context)).toEqual(
new Strategy(content, contextStrategy(context), domStrategy()),
new Strategy(content, contextStrategy(context), domStrategy())
);
},
}
);
});

@ -1,4 +1,9 @@
import { createHttpFactory, HttpMethod, SpectatorHttp, SpyObject } from '@ngneat/spectator/jest';
import {
createHttpFactory,
HttpMethod,
SpectatorHttp,
SpyObject,
} from '@ngneat/spectator/jest';
import { Store } from '@ngxs/store';
import { OAuthService } from 'angular-oauth2-oidc';
import { of, throwError } from 'rxjs';
@ -15,8 +20,11 @@ describe('HttpClient testing', () => {
const api = 'https://abp.io';
const createHttp = createHttpFactory({
dataService: RestService,
providers: [EnvironmentService, { provide: CORE_OPTIONS, useValue: { environment: {} } }],
service: RestService,
providers: [
EnvironmentService,
{ provide: CORE_OPTIONS, useValue: { environment: {} } },
],
mocks: [OAuthService, Store],
});
@ -57,7 +65,11 @@ describe('HttpClient testing', () => {
test('should use the specific api', () => {
spectator.service
.request({ method: HttpMethod.GET, url: '/test' }, null, 'http://test.api')
.request(
{ method: HttpMethod.GET, url: '/test' },
null,
'http://test.api'
)
.subscribe();
spectator.expectOne('http://test.api' + '/test', HttpMethod.GET);
});
@ -70,10 +82,12 @@ describe('HttpClient testing', () => {
spectator.expectOne('bar' + '/test', HttpMethod.GET);
});
test('should complete upon successful request', done => {
test('should complete upon successful request', (done) => {
const complete = jest.fn(done);
spectator.service.request({ method: HttpMethod.GET, url: '/test' }).subscribe({ complete });
spectator.service
.request({ method: HttpMethod.GET, url: '/test' })
.subscribe({ complete });
const req = spectator.expectOne(api + '/test', HttpMethod.GET);
spectator.flushAll([req], [{}]);
@ -83,13 +97,16 @@ describe('HttpClient testing', () => {
const spy = jest.spyOn(store, 'dispatch');
spectator.service
.request({ method: HttpMethod.GET, url: '/test' }, { observe: Rest.Observe.Events })
.request(
{ method: HttpMethod.GET, url: '/test' },
{ observe: Rest.Observe.Events }
)
.pipe(
catchError(err => {
catchError((err) => {
expect(err).toBeTruthy();
expect(spy).toHaveBeenCalled();
return of(null);
}),
})
)
.subscribe();
@ -103,14 +120,14 @@ describe('HttpClient testing', () => {
spectator.service
.request(
{ method: HttpMethod.GET, url: '/test' },
{ observe: Rest.Observe.Events, skipHandleError: true },
{ observe: Rest.Observe.Events, skipHandleError: true }
)
.pipe(
catchError(err => {
catchError((err) => {
expect(err).toBeTruthy();
expect(spy).toHaveBeenCalledTimes(0);
return of(null);
}),
})
)
.subscribe();

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -1,25 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AuthWrapperComponent } from './auth-wrapper.component';
describe('AuthWrapperComponent', () => {
let component: AuthWrapperComponent;
let fixture: ComponentFixture<AuthWrapperComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ AuthWrapperComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(AuthWrapperComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -1,25 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TenantBoxComponent } from './tenant-box.component';
describe('TenantBoxComponent', () => {
let component: TenantBoxComponent;
let fixture: ComponentFixture<TenantBoxComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ TenantBoxComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(TenantBoxComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"esModuleInterop": true
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]

@ -11,9 +11,8 @@
"target": "es2015",
"module": "esnext",
"lib": ["es2017", "dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"baseUrl": ".",
"allowSyntheticDefaultImports": true,
"paths": {
"@abp/ng.account": ["packages/account/src/public-api.ts"],
"@abp/ng.account.core": ["packages/account-core/src/public-api.ts"],

@ -11,8 +11,7 @@
"target": "es2015",
"module": "esnext",
"lib": ["es2017", "dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"@abp/ng.account": ["dist/packages/account"],

Loading…
Cancel
Save