With an Angular Service that leverages a TypeScript model module to add some functionality, how can you stub the models methods?
Below is a super simplistic example, how can the #aServiceMethod method be tested without running the actual MyModel constructor?
_models/my-model.ts
class MyModel {
name: string;
constructor(attrs?: object) {
Object.assign(this, attrs);
this.doSomeStuff();
}
prive doSomeStuff() {
this.name = this.name.toLowerCase();
}
}
_services/some-service.ts
import { MyModel } from '@models/index';
...
public aServiceMethod(attrs) {
return new MyModel(attrs);
}
Aucun commentaire:
Enregistrer un commentaire