gpt4 book ai didi

jasmine - Jasmine spyOn与特定的论点

转载 作者:行者123 更新时间:2023-12-03 12:40:57 26 4
gpt4 key购买 nike

假设我有

spyOn($cookieStore,'get').and.returnValue('abc');

对于我的用例来说,这太笼统了。任何时候我们打电话
$cookieStore.get('someValue') -->  returns 'abc'
$cookieStore.get('anotherValue') --> returns 'abc'

我想设置一个spyOn,以便根据参数获得不同的返回:
$cookieStore.get('someValue') -->  returns 'someabc'
$cookieStore.get('anotherValue') --> returns 'anotherabc'

有什么建议?

最佳答案

您可以使用callFake:

spyOn($cookieStore,'get').and.callFake(function(arg) {
if (arg === 'someValue'){
return 'someabc';
} else if(arg === 'anotherValue') {
return 'anotherabc';
}
});

关于jasmine - Jasmine spyOn与特定的论点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37035321/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com