Bonjour à tous,

Je fait des tests unitaires sur un composant. sur TypeScript et Jasmine
Seulement je doit setter la valeur de la classe parent ce que n'arrive pas a faire.

voici mon code de la classe enfant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
...
export class MyChildComponent extends MyParentComponent {
 
    .........
     myFunnyFuntion() {
         console.log('here I need to set my value this.propertyParent', this.propertyParent);
         // in the test I setted propertyParent to false but it still to 'true' in here !!??
         if(this.propertyParent === false)
          {
              dosometing..
          }
      }
}
et ma classe parent:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
.....
export class MyParentComponent {
 
   ......
   protected propertyParent: boolean = true;
   ......
    get propertyParent(): boolean {
       return this.propertyParent;
    }
 
    set propertyParent(value: boolean) {
        this.propertyParent = value;
    }
}
et pour les tests unitaire je fait:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
describe('Component tests', () => {
   let fixture: ComponentFixture<MyChildComponent>;
   let component: MyChildComponent;
   beforeEach(() => {
        ....... 
        // initiate child component
        fixture = TestBed.createComponent(MyChildComponent);
        component = fixture.componentInstance;
   }
   it('should be set the value propertyParent', () => {
       spyOn(component, 'propertyParent'); 
       // here I want to access to propertyParent, by default is setted to true
       component.propertyParent = false;
       // !!!!  the test is passing, 
       expect(component.propertyParent).toBe(false);
       // but my expectation is to enter into the condition in ChildComponent. never enter in it
       component.myFunnyFunction();
       fixture.detectChanges();
 
}