0.14.0 • Published 2 years ago
ng-stubs v0.14.0
ng-stubs
Create stubs for your Angular components and directives dynamically.
Installation
npm install --save-dev https://github.com/planser/ng-stubs.git
Example Usage
import { Component, OnInit, EventEmitter, Input, Output } from '@angular/core';
@Component({
selector: 'app-greeter',
template: '<button (click)="onClick()">Say Hi</button>',
styleUrls: ['./greeter.component.css']
})
export class GreeterComponent {
@Input()
name: string;
@Output()
greet = new EventEmitter<string>();
onClick(): void {
this.greet.emit(`Hi, ${this.name}`);
}
}
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `
<div><app-greeter [name]="name" (greet)="onGreet($event)"></app-greeter></div>
<div class="result">{{greeting}}</div>
`,
styleUrls: ['./app.component.css']
})
export class AppComponent {
name = "A Name";
greeting: string;
onGreet(greeting: string): void {
this.greeting = greeting;
}
}
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import { StubbedComponent, ComponentStub } from 'ng-stubs';
import { AppComponent } from './app.component';
import { GreeterComponent } from './greeter/greeter.component';
import { By } from '@angular/platform-browser';
describe('AppComponent', () => {
let fixture: ComponentFixture<AppComponent>;
let app: AppComponent;
let greeterComponentStub: StubbedComponent<GreeterComponent>;
beforeEach(async(() => {
greeterComponentStub = ComponentStub(GreeterComponent)
TestBed.configureTestingModule({
declarations:
[
AppComponent,
greeterComponentStub.type
]
}).compileComponents();
}));
beforeEach(async () => {
fixture = TestBed.createComponent(AppComponent);
app = fixture.debugElement.componentInstance;
fixture.detectChanges();
});
it('should create the app', () => {
expect(app).toBeTruthy();
});
it('binds the name to the greeter', () => {
expect(greeterComponentStub.instance.name).toEqual(app.name);
app.name = "Tester";
fixture.detectChanges();
expect(greeterComponentStub.instance.name).toEqual("Tester");
});
it('shows the greeter`s result', () => {
greeterComponentStub.instance.greet.emit("Hi, Tester");
fixture.detectChanges();
expect(fixture.debugElement.query(By.css(".result")).nativeElement.textContent).toEqual("Hi, Tester");
});
});
0.14.0
2 years ago
0.12.0
3 years ago
0.13.0
3 years ago
0.11.0
4 years ago
0.10.0
4 years ago
0.9.3
4 years ago
0.9.2
4 years ago
0.9.1
4 years ago
0.9.0
4 years ago
0.8.3
5 years ago
0.8.2-3
5 years ago
0.8.2-2
5 years ago
0.8.2-1
5 years ago
0.8.2
5 years ago
0.8.1
5 years ago
0.8.0
5 years ago
0.7.2
6 years ago
0.7.1
6 years ago
0.7.0
6 years ago
0.0.5
6 years ago
0.0.4
7 years ago
0.0.3
7 years ago
0.0.2
7 years ago
0.0.1
7 years ago