allenhwkim / allenhwkim/ngentest

[QUESTION] How to mock properly

Abierto
#74 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
142
Forks
53
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hi, i'm trying to make the library work on a angular project with test in karma framework
1. gentest seems to search for a ngentest.config.js in the current directory, not in my appdata node module folder.
2. When i generate the unit test from this class

import { Component, Input } from '@angular/core';
import { FiltreLocalStorageService } from 'src/app/service/filter-local-storage/filter-local-storage.service';
import { FiltreDataService } from 'src/app/service/filtre-data/filtre-data.service';
import { SecurityService } from 'src/app/service/security/security.service';

@Component({
selector: 'app-filtre-numero-serie',
templateUrl: './filtre-numero-serie.component.html',
styleUrls: ['./filtre-numero-serie.component.scss']
})
export class FiltreNumeroSerieComponent {

@Input() vue: string;

numeroSerie: string = ''
placeholder: string = "Numéro de série"

constructor(private filtreDataService: FiltreDataService,private storageService :FiltreLocalStorageService,private securityService : SecurityService) { }

onKeyEnter(event: any) {
this.filtreDataService.updateFilter(this.vue, { numeroSerie: this.numeroSerie.trim() });
this.securityService.logUserActivityObservable('Vue Borne, utilisation du filtre: matricule valeur ' + this.numeroSerie)
}

getNumeroSerie(){
this.filtreDataService.updateFilter(this.vue, { numeroSerie: this.numeroSerie.trim() });
}

ngOnInit(){
let filtresInStorage = this.storageService.getFiltres(this.vue)
this.numeroSerie = filtresInStorage ? filtresInStorage.numSerie : ''
this.filtreDataService.subscribeToVue(this.vue,(filtreData) => this.numeroSerie = filtreData.numeroSerie)
}

}

I got this test generate

// @ts-nocheck
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Pipe, PipeTransform, Injectable, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, Directive, Input, Output } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { Observable, of as observableOf, throwError } from 'rxjs';

import { Component } from '@angular/core';
import { FiltreNumeroSerieComponent } from './filtre-numero-serie.component';
import { FiltreDataService } from 'src/app/service/filtre-data/filtre-data.service';
import { FiltreLocalStorageService } from 'src/app/service/filter-local-storage/filter-local-storage.service';
import { SecurityService } from 'src/app/service/security/security.service';

@Injectable()
class MockFiltreDataService {}

@Injectable()
class MockFiltreLocalStorageService {}

@Injectable()
class MockSecurityService {}

@Directive({ selector: '[myCustom]' })
class MyCustomDirective {
@Input() myCustom;
}

.....

Mock are not generated properly, how can i config that ?

Thanks

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.