testing - How to test angular 2 directive Supplied parameters do not match any signature of call target -
i have directive want test. every time run test, error says 'supplied parameters not match signature of call target'. how parameters of constructor test?
this directive:
import { directive, elementref, hostlistener, input, renderer } '@angular/core'; @directive({ selector: '[fbinputlistener]' }) export class inputlistenerdirective { constructor( private elref: elementref, private renderer: renderer ) { } @hostlistener('keyup') onkeyup() { if(this.elref.nativeelement.value.length > 0) { this.renderer.setelementclass(this.elref.nativeelement, 'form__input--has-value', true); } else { this.renderer.setelementclass(this.elref.nativeelement, 'form__input--has-value', false); } } } this it's test:
import { inputlistenerdirective } './inputlistener.directive'; describe('inputlistenerdirective', () => { it('should create instance', () => { const directive = new inputlistenerdirective(); expect(directive).tobetruthy(); }); });
import {testbed, componentfixture} '@angular/core/testing'; import {by} "@angular/platform-browser"; import {component, debugelement} "@angular/core"; import { inputlistenerdirective } './inputlistener.directive'; @component({ template: `<input type="number" fbinputlistener value="12345">` }) class testinputcomponent { } describe('inputlistenerdirective', () => { let component: testinputcomponent; let fixture: componentfixture<testinputcomponent>; let inputel: debugelement; beforeeach(() => { testbed.configuretestingmodule({ declarations: [testinputcomponent, inputlistenerdirective] }); fixture = testbed.createcomponent(testinputcomponent); component = fixture.componentinstance; inputel = fixture.debugelement.query(by.css('input')); }); it('directive should add class test input', () => { inputel.triggereventhandler('keyup', null); fixture.detectchanges(); expect(inputel.nativeelement.classlist.length).tobe(1); }); });
Comments
Post a Comment