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,
- You can remove the
serviceTData
fromasync function setSTNo (serviceTData)
parameter list - Add a
useEffect
to listen for the changes in theserviceTData
item and then call the functionsetSTNo
whenever theserviceTData
is updated. - 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
How to Make a Uitextfield Move Up When the Keyboard Is Present - on Starting to Edit
Uiview With Rounded Corners and Drop Shadow
Ios Launching Settings -≫ Restrictions Url Scheme
How to Develop For Iphone Using a Windows Development Machine
Presenting Modal in iOS 13 Fullscreen
How to Force Nslocalizedstring to Use a Specific Language
Determine Device (Iphone, Ipod Touch) With Ios
How to Debug 'Unrecognized Selector Sent to Instance' Error
Undefined Symbols For Architecture Armv7
The Simplest Way to Resize an Uiimage
Send and Receive Messages Through Nsnotificationcenter in Objective-C
How to Add Constraints Programmatically Using Swift
Firebase - Deleting and Reinstalling App Does Not Un-Authenticate a User
Uiscrollview Scrollable Content Size Ambiguity
How to Detect Avplayer and Get Url of Current Video from Wkwebview
How to Create a Custom iOS View Class and Instantiate Multiple Copies of It (In Ib)