Skip to content

Commit

Permalink
fix: grouping similarities
Browse files Browse the repository at this point in the history
  • Loading branch information
satanTime committed Jan 5, 2021
1 parent 8b372fb commit e1bc77b
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 32 deletions.
5 changes: 4 additions & 1 deletion lib/common/core.reflect.directive-resolve.ts
@@ -1,6 +1,9 @@
import { MockDirectiveResolver } from '@angular/compiler/testing';
import { Directive } from '@angular/core';

import coreReflectBodyCatch from './core.reflect.body-catch';
import coreReflectDirective from './core.reflect.directive';
import coreReflectBodyGlobal from './core.reflect.body-global';

const coreReflectDirective = coreReflectBodyGlobal(MockDirectiveResolver);

export default (def: any): Directive => coreReflectBodyCatch((arg: any) => coreReflectDirective().resolve(arg))(def);
5 changes: 0 additions & 5 deletions lib/common/core.reflect.directive.ts

This file was deleted.

5 changes: 4 additions & 1 deletion lib/common/core.reflect.module-resolve.ts
@@ -1,6 +1,9 @@
import { MockNgModuleResolver } from '@angular/compiler/testing';
import { NgModule } from '@angular/core';

import coreReflectBodyCatch from './core.reflect.body-catch';
import coreReflectModule from './core.reflect.module';
import coreReflectBodyGlobal from './core.reflect.body-global';

const coreReflectModule = coreReflectBodyGlobal(MockNgModuleResolver);

export default (def: any): NgModule => coreReflectBodyCatch((arg: any) => coreReflectModule().resolve(arg))(def);
5 changes: 0 additions & 5 deletions lib/common/core.reflect.module.ts

This file was deleted.

5 changes: 4 additions & 1 deletion lib/common/core.reflect.pipe-resolve.ts
@@ -1,6 +1,9 @@
import { MockPipeResolver } from '@angular/compiler/testing';
import { Pipe } from '@angular/core';

import coreReflectBodyCatch from './core.reflect.body-catch';
import coreReflectPipe from './core.reflect.pipe';
import coreReflectBodyGlobal from './core.reflect.body-global';

const coreReflectPipe = coreReflectBodyGlobal(MockPipeResolver);

export default (def: any): Pipe => coreReflectBodyCatch((arg: any) => coreReflectPipe().resolve(arg))(def);
5 changes: 0 additions & 5 deletions lib/common/core.reflect.pipe.ts

This file was deleted.

6 changes: 3 additions & 3 deletions lib/mock-builder/promise/get-override-meta.ts
@@ -1,14 +1,14 @@
import { Directive } from '@angular/core';

import coreReflectDirective from '../../common/core.reflect.directive';
import coreReflectDirectiveResolve from '../../common/core.reflect.directive-resolve';
import { isNgDef } from '../../common/func.is-ng-def';

export default (value: any): Directive | undefined => {
if (isNgDef(value, 'c')) {
return coreReflectDirective().resolve(value);
return coreReflectDirectiveResolve(value);
}
if (isNgDef(value, 'd')) {
return coreReflectDirective().resolve(value);
return coreReflectDirectiveResolve(value);
}

return undefined;
Expand Down
10 changes: 7 additions & 3 deletions lib/mock-module/mock-module.spec.ts
Expand Up @@ -19,7 +19,7 @@ import {
import { BrowserModule, By } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import coreReflectModule from '../common/core.reflect.module';
import coreReflectModuleResolve from '../common/core.reflect.module-resolve';
import ngMocksUniverse from '../common/ng-mocks-universe';
import { MockComponent } from '../mock-component/mock-component';
import { MockRender } from '../mock-render/mock-render';
Expand Down Expand Up @@ -242,15 +242,19 @@ describe('mockProvider', () => {

it('should skip multi tokens in a mock module', () => {
const mock = MockModule(CustomTokenModule);
const def = coreReflectModule().resolve(mock);
const def = coreReflectModuleResolve(mock);
expect(def.providers).toEqual([
{
deps: [Injector],
provide: CUSTOM_TOKEN,
useFactory: jasmine.anything(),
},
]);
expect(def.providers?.[0].useFactory()).toEqual('');

const provider: any = !Array.isArray(def.providers?.[0])
? def.providers?.[0]
: undefined;
expect(provider?.useFactory()).toEqual('');
});

it('should return undefined on any token', () => {
Expand Down
8 changes: 4 additions & 4 deletions tests/issue-145/components.spec.ts
@@ -1,7 +1,7 @@
import { Component } from '@angular/core';
import { NG_VALIDATORS, NG_VALUE_ACCESSOR } from '@angular/forms';
import { MockComponent } from 'ng-mocks';
import coreReflectDirective from 'ng-mocks/dist/lib/common/core.reflect.directive';
import coreReflectDirectiveResolve from 'ng-mocks/dist/lib/common/core.reflect.directive-resolve';

@Component({
selector: 'component',
Expand Down Expand Up @@ -38,7 +38,7 @@ export class ComponentValidator {}
describe('issue-145:components', () => {
it('does not add NG_VALUE_ACCESSOR to components', () => {
const mock = MockComponent(ComponentDefault);
const { providers } = coreReflectDirective().resolve(mock);
const { providers } = coreReflectDirectiveResolve(mock);
expect(providers).toEqual([
{
provide: ComponentDefault,
Expand All @@ -49,7 +49,7 @@ describe('issue-145:components', () => {

it('adds NG_VALUE_ACCESSOR to components that provide it', () => {
const mock = MockComponent(ComponentValueAccessor);
const { providers } = coreReflectDirective().resolve(mock);
const { providers } = coreReflectDirectiveResolve(mock);
expect(providers).toEqual([
{
provide: ComponentValueAccessor,
Expand All @@ -65,7 +65,7 @@ describe('issue-145:components', () => {

it('respects NG_VALIDATORS too', () => {
const mock = MockComponent(ComponentValidator);
const { providers } = coreReflectDirective().resolve(mock);
const { providers } = coreReflectDirectiveResolve(mock);
expect(providers).toEqual([
{
provide: ComponentValidator,
Expand Down
8 changes: 4 additions & 4 deletions tests/issue-145/directives.spec.ts
@@ -1,7 +1,7 @@
import { Directive } from '@angular/core';
import { NG_VALIDATORS, NG_VALUE_ACCESSOR } from '@angular/forms';
import { MockDirective } from 'ng-mocks';
import coreReflectDirective from 'ng-mocks/dist/lib/common/core.reflect.directive';
import coreReflectDirectiveResolve from 'ng-mocks/dist/lib/common/core.reflect.directive-resolve';

@Directive({
selector: 'directive',
Expand Down Expand Up @@ -36,7 +36,7 @@ export class DirectiveValidator {}
describe('issue-145:directives', () => {
it('does not add NG_VALUE_ACCESSOR to directives', () => {
const mock = MockDirective(DirectiveDefault);
const { providers } = coreReflectDirective().resolve(mock);
const { providers } = coreReflectDirectiveResolve(mock);
expect(providers).toEqual([
{
provide: DirectiveDefault,
Expand All @@ -47,7 +47,7 @@ describe('issue-145:directives', () => {

it('adds NG_VALUE_ACCESSOR to directives that provide it', () => {
const mock = MockDirective(DirectiveValueAccessor);
const { providers } = coreReflectDirective().resolve(mock);
const { providers } = coreReflectDirectiveResolve(mock);
expect(providers).toEqual([
{
provide: DirectiveValueAccessor,
Expand All @@ -63,7 +63,7 @@ describe('issue-145:directives', () => {

it('respects NG_VALIDATORS too', () => {
const mock = MockDirective(DirectiveValidator);
const { providers } = coreReflectDirective().resolve(mock);
const { providers } = coreReflectDirectiveResolve(mock);
expect(providers).toEqual([
{
provide: DirectiveValidator,
Expand Down

0 comments on commit e1bc77b

Please sign in to comment.