0

How can i do unit test on sample TypeSCript function below? I'm trying to incorporate unit test with SharePoint Framework using PNP/SP library and having issues with creating the unit test.

public getListItems(): Promise<CustomListObject[]> {
        return new Promise<CustomListObject[]>((resolve, reject) => {
            let listObjects: CustomListObject[] = [];
            this.sp.web.lists.getByTitle('TestList').items
                .select('Title')
                .filter('IsValidItem eq \'Yes\'')
                .get().then(
                    (allItems: any[]) => {
                        allItems.forEach(item => {
                            listObjects.push({ 'title': item.Title });
                        });
                        resolve(listObjects);
                    }).catch(
                        error => {
                            console.log(error);
                            reject(error);
                        }
                    );
        });
    }
asepdf
  • 13
  • 3

1 Answers1

0

You can start with Jest Async: https://jestjs.io/docs/en/tutorial-async

Ruslan Korkin
  • 3,973
  • 1
  • 27
  • 23