Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] How to mock properly #74

Open
NoXeoZ opened this issue Mar 18, 2024 · 0 comments
Open

[QUESTION] How to mock properly #74

NoXeoZ opened this issue Mar 18, 2024 · 0 comments

Comments

@NoXeoZ
Copy link

NoXeoZ commented Mar 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant