How to use the ng-mocks.MockRender function in ng-mocks

To help you get started, we’ve selected a few ng-mocks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ike18t / ng-mocks / examples / MockComponent / MockComponent.spec.ts View on Github external
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');
github ike18t / ng-mocks / examples / MockRender / MockRender.spec.ts View on Github external
it('renders template', () =&gt; {
    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))
github ike18t / ng-mocks / examples / MockRender / MockRender.spec.ts View on Github external
it('renders component', () =&gt; {
    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');
  });
});
github ike18t / ng-mocks / examples / MockComponent / MockComponent.spec.ts View on Github external
it('should render something inside of the dependency component', () =&gt; {
    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>');
  });
github ike18t / ng-mocks / e2e / context-with-directives / context-with-directives.spec.ts View on Github external
it('renders everything what is not template', () =&gt; {
    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] }}
github ike18t / ng-mocks / e2e / context-with-directives / context-with-directives.spec.ts View on Github external
it('renders everything right', () =&gt; {
    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] }}

ng-mocks

An Angular testing library for creating mock services, components, directives, pipes and modules in unit tests. It provides shallow rendering, precise stubs to fake child dependencies. ng-mocks works with Angular 5 6 7 8 9 10 11 12 13 14 15 16 17 18, jasm

MIT
Latest version published 2 months ago

Package Health Score

89 / 100
Full package analysis