diff --git a/npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts new file mode 100644 index 0000000000..c1d324620d --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts @@ -0,0 +1,46 @@ +import { PermissionDirective } from '../directives/permission.directive'; +import { SpectatorDirective, createDirectiveFactory, SpyObject } from '@ngneat/spectator/jest'; +import { Store } from '@ngxs/store'; +import { of, Subject } from 'rxjs'; + +describe('PermissionDirective', () => { + let spectator: SpectatorDirective; + let directive: PermissionDirective; + const grantedPolicy$ = new Subject(); + + const createDirective = createDirectiveFactory({ + directive: PermissionDirective, + providers: [{ provide: Store, useValue: { select: () => grantedPolicy$ } }], + }); + + describe('with condition', () => { + beforeEach(() => { + spectator = createDirective(`
Testing Permission Directive
`); + directive = spectator.directive; + }); + + it('should be created', () => { + expect(directive).toBeTruthy(); + }); + + it('should remove the element from DOM', () => { + grantedPolicy$.next(true); + expect(spectator.query('#test-element')).toBeTruthy(); + grantedPolicy$.next(false); + expect(spectator.query('#test-element')).toBeFalsy(); + }); + }); + + describe('without condition', () => { + beforeEach(() => { + spectator = createDirective('
Testing Permission Directive
'); + directive = spectator.directive; + }); + + it('should do nothing when condition is undefined', () => { + const spy = jest.spyOn(spectator.get(Store), 'select'); + grantedPolicy$.next(false); + expect(spy.mock.calls).toHaveLength(0); + }); + }); +}); diff --git a/npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts index 6a06ec2c12..3d5cc11287 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts @@ -62,7 +62,7 @@ describe('HttpClient testing', () => { }); test('should handle the error', () => { - jest.spyOn(spectator.httpClient, 'request').mockReturnValue(throwError('An error')); + jest.spyOn(spectator.httpClient, 'request').mockReturnValue(throwError('Testing error')); const spy = jest.spyOn(store, 'dispatch'); spectator.service @@ -78,7 +78,7 @@ describe('HttpClient testing', () => { }); test('should not handle the error when skipHandleError is true', () => { - jest.spyOn(spectator.httpClient, 'request').mockReturnValue(throwError('An error')); + jest.spyOn(spectator.httpClient, 'request').mockReturnValue(throwError('Testing error')); const spy = jest.spyOn(store, 'dispatch'); spectator.service