this
.
If your function does not access this
, you can annotate it with this: void
, or consider using an arrow function instead 90 saveSubject.complete();
91
92 // THEN
93 expect(topicService.create).toHaveBeenCalledWith(topic); 94 expect(comp.isSaving).toEqual(false);
95 expect(comp.previousState).toHaveBeenCalled();
96 });
this
.
If your function does not access this
, you can annotate it with this: void
, or consider using an arrow function instead 92 // THEN
93 expect(topicService.create).toHaveBeenCalledWith(topic);
94 expect(comp.isSaving).toEqual(false);
95 expect(comp.previousState).toHaveBeenCalled(); 96 });
97
98 it('Should set isSaving to false on error', () => {
this
.
If your function does not access this
, you can annotate it with this: void
, or consider using an arrow function instead112 // THEN
113 expect(topicService.update).toHaveBeenCalledWith(topic);
114 expect(comp.isSaving).toEqual(false);
115 expect(comp.previousState).not.toHaveBeenCalled();116 });
117 });
118});
this
.
If your function does not access this
, you can annotate it with this: void
, or consider using an arrow function instead 70
71 // THEN
72 expect(comp.previousState).toHaveBeenCalled();
73 expect(topicService.update).toHaveBeenCalledWith(topic); 74 expect(comp.isSaving).toEqual(false);
75 });
76
this
.
If your function does not access this
, you can annotate it with this: void
, or consider using an arrow function instead 69 saveSubject.complete();
70
71 // THEN
72 expect(comp.previousState).toHaveBeenCalled(); 73 expect(topicService.update).toHaveBeenCalledWith(topic);
74 expect(comp.isSaving).toEqual(false);
75 });
Warning is raised when a method is used outside of a method call.
Class functions don't preserve the class scope when passed as standalone variables.
class MyClass {
public log(): void {
console.log(this);
}
}
const instance = new MyClass();
// This logs the global scope (`window`/`global`), not the class instance
const myLog = instance.log;
myLog();
// This log might later be called with an incorrect scope
const { log } = instance;
class MyClass {
public logUnbound(): void {
console.log(this);
}
public logBound = () => console.log(this);
}
const instance = new MyClass();
// logBound will always be bound with the correct scope
const { logBound } = instance;
logBound();
// .bind and lambdas will also add a correct scope
const dotBindLog = instance.logBound.bind(instance);
const innerLog = () => instance.logBound();