Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should render something inside of the dependency component', () => {
const localFixture = MockRender(`
<p>inside template</p>
<p>inside content</p>
`);
// injected ng-content says as it was.
const mockedNgContent = localFixture.debugElement
.query(By.directive(DependencyComponent))
.nativeElement.innerHTML;
expect(mockedNgContent).toContain('<p>inside content</p>');
// because component does have @ContentChild we need to render them first with proper context.
const mockedElement = localFixture.debugElement.query(By.directive(DependencyComponent));
const mockedComponent: MockedComponent = mockedElement.componentInstance;
mockedComponent.__render('something');
it('renders template', () => {
const spy = jasmine.createSpy();
const fixture = MockRender(
`
something as ng-template
something as ng-content
`,
{
myListener1: spy,
myParam1: 'something1',
}
);
// assert on some side effect
const componentInstance = fixture.debugElement.query(By.directive(TestedComponent))
it('renders component', () => {
const spy = jasmine.createSpy();
// generates template like:
//
// and returns fixture with a component with properties value1, value2 and empty callback trigger.
const fixture = MockRender(TestedComponent, {
trigger: spy,
value1: 'something2',
});
// assert on some side effect
const componentInstance = fixture.debugElement.query(By.directive(TestedComponent))
.componentInstance as TestedComponent;
componentInstance.trigger.emit('foo2');
expect(componentInstance.value1).toEqual('something2');
expect(componentInstance.value2).toBeUndefined();
expect(spy).toHaveBeenCalledWith('foo2');
});
});
it('should render something inside of the dependency component', () => {
const localFixture = MockRender(`
<p>inside content</p>
`);
// because component does not have any @ContentChild we can access html directly.
// assert on some side effect
const mockedNgContent = localFixture.debugElement
.query(By.directive(DependencyComponent))
.nativeElement.innerHTML;
expect(mockedNgContent).toContain('<p>inside content</p>');
});
it('renders everything what is not template', () => {
const fixture = MockRender(`
<div>header</div>
template w/ directive w/o binding
template w/ directive w/ binding {{ value[0] }}
template w/ directive w/ binding {{ value[0] }}
template w/o directive w/o binding
template w/o directive w/ binding {{ value[0] }}
it('renders everything right', () => {
const fixture = MockRender(`
<div>header</div>
template w/ directive w/o binding
template w/ directive w/ binding {{ value[0] }}
template w/ directive w/ binding w/o render
template w/o directive w/o binding
template w/o directive w/ binding {{ value[0] }}