Skip to content

Commit

Permalink
feat(rx): increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbe812 committed Jan 16, 2023
1 parent 331c44c commit 75abc51
Show file tree
Hide file tree
Showing 22 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createElementRef, mockIntersectionObserver} from '@angular-kit/testing';
import {createElementRef, mockIntersectionObserver} from '@angular-kit/test-helpers';
import {createIntersectionObserver} from './create-intersection-observer';
import {subscribeSpyTo} from '@hirez_io/observer-spy';
import {fakeAsync, tick} from '@angular/core/testing';
Expand Down
2 changes: 1 addition & 1 deletion libs/rx/platform/src/lib/create-mutation-observer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createMutationObserver} from './create-mutation-observer';
import {subscribeSpyTo} from '@hirez_io/observer-spy';
import {createElementRef, mockMutationObserver} from '@angular-kit/testing';
import {createElementRef, mockMutationObserver} from '@angular-kit/test-helpers';
import {fakeAsync, tick} from '@angular/core/testing';

describe('createMutationObserver', () => {
Expand Down
2 changes: 1 addition & 1 deletion libs/rx/platform/src/lib/create-resize-observer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {createResizeObserver} from './create-resize-observer';
import {fakeAsync, tick} from '@angular/core/testing';
import {subscribeSpyTo} from '@hirez_io/observer-spy';
import {createElementRef, mockResizeObserver} from '@angular-kit/testing';
import {createElementRef, mockResizeObserver} from '@angular-kit/test-helpers';

describe('createResizeObserver', () => {
describe('supported', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Directive, NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';

@Directive({
selector: '[angularKitObserveIntersection]',
selector: '[observeIntersection]',
})
export class ObserveIntersectionDirective {
// todo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import {ObserveResizeDirective, ObserveResizeDirectiveModule} from './observe-resize.directive';
import {Component} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {mockResizeObserver} from '@angular-kit/testing';
import {Component, ViewChild} from '@angular/core';
import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {mockResizeObserver} from '@angular-kit/test-helpers';
import {subscribeSpyTo} from "@hirez_io/observer-spy";

describe('ObserveResizeDirective', () => {
it('should create an instance', async () => {
const { testComponent } = await create();
expect(testComponent).toBeTruthy();
});

it('should emit on resize', fakeAsync (async () => {
const {testComponent, fixture} = await create();
const result = subscribeSpyTo(testComponent.directive.resizeEvent);

fixture.nativeElement.dispatchEvent(new Event('resize'));
tick(1000)
expect(result.getValues().length).toEqual(1)
}));
});

async function create() {
Expand All @@ -26,6 +36,7 @@ async function create() {
`,
})
class TestComponent {
@ViewChild(ObserveResizeDirective, {static: true}) directive!: ObserveResizeDirective;
onResize = jest.fn();
observe = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {Directive, ElementRef, Input, NgModule, OnDestroy, Output} from '@angula
import {CommonModule} from '@angular/common';
import {Subscription} from 'rxjs';
import {createResizeObserver, ResizeObserverConfig} from '../create-resize-observer';
import {createSignal} from '@code-workers.io/angular-kit/rx/signal';
import {Nullable} from '@code-workers.io/angular-kit/cdk/types';
import {createSignal} from '@angular-kit/rx/signal';
import {Nullable} from '@angular-kit/cdk/types';

@Directive({
selector: '[observeResize]',
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions libs/testing/README.md β†’ libs/test-helpers/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# testing
# test-helpers

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test testing` to execute the unit tests.
Run `nx test test-helpers` to execute the unit tests.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
export default {
displayName: 'testing',
displayName: 'test-helpers',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
Expand All @@ -9,7 +9,7 @@ export default {
stringifyContentPathRegex: '\\.(html|svg)$',
},
},
coverageDirectory: '../../coverage/libs/testing',
coverageDirectory: '../../coverage/libs/test-helpers',
transform: {
'^.+\\.(ts|mjs|js|html)$': 'jest-preset-angular',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/libs/testing",
"dest": "../../dist/libs/test-helpers",
"lib": {
"entryFile": "src/index.ts"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@angular-kit/testing",
"name": "@angular-kit/test-helpers",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^15.0.0",
Expand Down
41 changes: 41 additions & 0 deletions libs/test-helpers/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "test-helpers",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"sourceRoot": "libs/test-helpers/src",
"prefix": "angular-kit",
"targets": {
"build": {
"executor": "@nrwl/angular:ng-packagr-lite",
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
"options": {
"project": "libs/test-helpers/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "libs/test-helpers/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "libs/test-helpers/tsconfig.lib.json"
}
},
"defaultConfiguration": "production"
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/test-helpers/jest.config.ts",
"passWithNoTests": true
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/test-helpers/**/*.ts", "libs/test-helpers/**/*.html"]
}
}
},
"tags": []
}
3 changes: 3 additions & 0 deletions libs/test-helpers/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './lib/test-helpers.module';
export * from './lib/rx/observable-testing';
export * from './lib/rx/platform.testing';
7 changes: 7 additions & 0 deletions libs/test-helpers/src/lib/test-helpers.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';

@NgModule({
imports: [CommonModule],
})
export class TestHelpersModule {}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@angular-kit/rx/query": ["libs/rx/query/src/index.ts"],
"@angular-kit/rx/signal": ["libs/rx/signal/src/index.ts"],
"@angular-kit/stream": ["libs/stream/src/index.ts"],
"@angular-kit/testing": ["libs/testing/src/index.ts"],
"@angular-kit/test-helpers": ["libs/test-helpers/src/index.ts"],
"@code-workers.io/angular-kit/rx/effect": ["libs/rx/effect/src/index.ts"]
}
},
Expand Down

0 comments on commit 75abc51

Please sign in to comment.