这是我第一次参与FrontEnd单元测试(Sharepoint Web Part)。我的问题是我想为服务层编写单元测试,但我还没有弄清楚如何检索 Sharepoint 上下文以传递到类构造函数中。
export class CRUDService implements ICRUDService {
private _context: any;
constructor(private context: any) {
context = this._context;
}
sp = spfi().using(SPFx(this.context));
/*
Service logic
*/
使用 Jest 为 SharePoint 框架 (SPFx) Web 部件编写单元测试时,通常使用 Jest 的模拟功能来模拟不同的场景。此外,您可能想要模拟 SharePoint 框架上下文 (ISPFXContext) 以提供受控的测试环境。