Macros or Transformations to improve unit test writing
I'm trying to improve my unit test writing. I'm not doing TDD. I'm doing tests after writing the majority of my code.
One thing I do repeatedly is mock services injected into my Angular components. So I need to take this
constructor(
private _activatedRoute: ActivatedRoute,
private _authorizationService: AuthorizationService,
private _domSanitizer: DomSanitizer,
private _enterpriseConfigurationService: EnterpriseConfigurationDataAccessService,
private _router: Router,
private _toastr: ToastrService
)
And transform it into:
let activatedRoute: SpyObj<ActivatedRoute>;
let authorizationService: SpyObj<AuthorizationService>;
let domSanitizer: SpyObj<DomSanitizer>;
let enterpriseConfigurationService: SpyObj<EnterpriseConfigurationDataAccessService>;
let router: SpyObj<Router>;
let toastr: SpyObj<ToastrService>;
afterAll(() => {
activatedRoute = null;
authorizationService = null;
domSanitizer = null;
enterpriseConfigurationService = null;
router = null;
toastr = null;
});
I've looked at macros but there is no real scripting capability there.
Are there any plugins that might help here or other options that I might pursue?
请先登录再写评论。
You can try using Structural Search and Replace (https://www.jetbrains.com/help/webstorm/2020.1/structural-search-and-replace.html) here, I suppose - see https://www.jetbrains.com/help/webstorm/2020.1/structural-search-and-replace-examples.html for some examples