I have a basic component that contains the ngxPermissionsOnly
directive which is working as expected. The library is on github here. I generated the component using the @angular-cli which also auto-generated the unit test.
e.g. Component
@Component({
selector: 'project-card',
template: '<div class="some-style"><div *ngxPermissionsOnly="['testPermission']"'>Hide Me</div></div>'
styleUrls: ['./project-card.component.scss']
})
export class ProjectCardComponent implements OnInit {
//Do some stuff here
}
e.g. Test
describe('ProjectCardComponent', () => {
let component: ProjectCardComponent;
let fixture: ComponentFixture<ProjectCardComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ProjectCardComponent,
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ProjectCardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
When I run the test I get the below error;
Can't bind to 'ngxPermissionsOnly' since it isn't a known property of 'div'
I tried adding the NgxPermissionsDirective
to the TestBed
declarations, however this directive is dependent on services from that library, and I would also have to inject them. I also tried importing the NgxPermissionsModule
itself but it has it's own errors. It seems counter-intuitive to inject a whole bunch of services to test a simple component. Is there a way to mock this directive? Or another solution?