Skip to content

Commit

Permalink
Merge pull request #268 from satanTime/issues/266
Browse files Browse the repository at this point in the history
fix: declarations w/o selectors are reachable with ngMocks helpers
  • Loading branch information
satanTime authored Jan 2, 2021
2 parents 2e229ce + ac26d81 commit 7e70fd4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/mock-render/mock-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ const applyParamsToFixtureInstance = (

const registerTemplateMiddleware = (template: AnyType<any>, meta: Directive): void => {
const child = extendClass(template);

let providers = meta.providers || [];
providers = [
...providers,
{
provide: template,
useExisting: child,
},
];
meta.providers = providers;

if (isNgDef(template, 'c')) {
Component(meta)(child);
} else {
Expand Down
12 changes: 11 additions & 1 deletion tests/issue-266/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Pipe,
PipeTransform,
} from '@angular/core';
import { MockBuilder, MockRender } from 'ng-mocks';
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';

@Component({
template: 'target',
Expand Down Expand Up @@ -60,6 +60,11 @@ describe('issue-248', () => {
);
expect(fixture.point.componentInstance.name).toEqual('component');
expect(fixture.point.nativeElement.innerHTML).toEqual('target');

expect(ngMocks.find(TargetComponent)).toBe(fixture.point);
expect(ngMocks.findInstance(TargetComponent)).toBe(
fixture.point.componentInstance,
);
});

it('renders directives', () => {
Expand All @@ -82,6 +87,11 @@ describe('issue-248', () => {
jasmine.any(TargetDirective),
);
expect(fixture.point.componentInstance.value).toEqual('321');

expect(ngMocks.find(TargetDirective)).toBe(fixture.point);
expect(ngMocks.findInstance(TargetDirective)).toBe(
fixture.point.componentInstance,
);
});

it('fails on not provided pipes', () => {
Expand Down

0 comments on commit 7e70fd4

Please sign in to comment.