-Didselectrowatindexpath: Not Being Called

How can I test that a function has not been called?

Use the not operator:

expect(controller.bar).not.toHaveBeenCalled();

Web API not being called from angular

Looks like you are forgot to subscribe to:

this.stops$ = this.apiService.getStopStatistics(id);
this.list$ = this.apiService.getList(id, '3');

I think this.stops$ works for you because somewhere in the template you have async pipe(stops$ | async).

So try to do:

this.list$.subscribe(response => console.log(response));

after that request should sent

Callback not being called

I haven't used mock so don't have know the ins and outs of how it handles parameters when mocking but you could do something like this to get around your problem.

public class CacheService : ICacheService
{
public T Get<T>(string cacheId, Func<T> getItemCallback) where T : class
{
var cacheExpiry = DateTime.UtcNow.AddMinutes(120);

var item = HttpRuntime.Cache.Get(cacheId) as T;
if (item == null)
{
item = getItemCallback();
HttpRuntime.Cache.Insert(cacheId, item, null, cacheExpiry, Cache.NoSlidingExpiration);
}
return item;
}

protected virtual InsertCache(string key, Object value, CacheDependency dependencies,
DateTime absoluteExpiration, TimeSpan slidingExpiration) {
HttpRuntime.Cache.Insert(key, value, dependencies, absoluteExpiration,
Cache.slidingExpiration);
}
}

Do the same with the calls to get the cacheExpiry and the Item and now in your test you can create a MockCacheService that overrides your CacheService with public properties that are used to return cacheExpiry and item from the overriden protected functions. Now you have got full control of your dependencies. Just another way of skinning the cat.

Function is not being called React native

The function setSTNo is expecting a parameter serviceTData which you are not passing down to it.
I'm guessing the serviceTData is one of your useState items and you want to call the function setSTNo whenever the serviceTData value is updated.

If so,

  1. You can remove the serviceTData from async function setSTNo (serviceTData) parameter list
  2. Add a useEffect to listen for the changes in the serviceTData item and then call the function setSTNo whenever the serviceTData is updated.
  3. remove the setSTNo function call from your API call then block.
 async function  setSTNo  ()  {
console.log("st No tryyy" )
try {
await AsyncStorage.setItem('STnumber', serviceTData.id);
setLaststNumber(serviceTData.id);
console.log("OLD st No" , LaststNumber);
} catch (e){
console.log("Error Part",e);
}
}

Then add a useEffect to listen to your serviceTData state.

useEffect(() => {
if(serviceTData)
setSTNo();
},[serviceTData]);

assuming the initial state of serviceTData is null.



Related Topics



Leave a reply



Submit