0

I'm working on a legacy AngularJS application that runs on SP. In its services, it's heavily using jQuery.SPServices to fetch/save data. This has made the services untestable. Is there an easy way to isolate these SP bound accesses from the rest of the application? I was thinking of mocking the services out and unit test the controllers only, but that leaves out the filter logic and whatnot built into services. Any pointers?

1 Answer 1

0

You could use axios to call SharePoint Rest api directly.

 var endPointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbyTitle('siteAdmins')/items";
        var headers = {
            "accept": "application/json;odata=verbose"
        };        
        axios.get(endPointUrl).then(response => {
            console.log(response.data.value);    
        });

How to use axios
SharePoint Rest Api

3
  • Thanks, but I read on thier page "axios is heavily inspired by the $http service provided in Angular. Ultimately axios is an effort to provide a standalone $http-like service for use outside of Angular." So I believe I'm better off with what Angular provides if I'm going to use the rest api. Don't you think? Commented Sep 30, 2020 at 3:06
  • axios is lighter than spservice.Of course,you could choose methods provided by Angular. Commented Sep 30, 2020 at 3:13
  • Hmm but that involves changing all my legacy code which uses SPServices to use the rest api. That's a massive change and a pretty risky one IMO given that I don't have any tests to verify the functionality. I wish there is a way to keep SPServices but somehow intercept and replace it with test doubles. Commented Oct 1, 2020 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.