小编Ang*_*elo的帖子

如何让Jasmine的spyOnProperty工作?

我看到这篇帖子后很兴奋地尝试了,但我无法让它发挥作用.试图保持这个简单只是为了弄清楚什么是错的,但即使这样也是失败的.

export class SomeService {
...
private _myValue: Boolean = false;
get myValue(): Boolean {
    return this._myValue;
}
set myValue(helper: Boolean) {
    this._myValue = helper;
}
Run Code Online (Sandbox Code Playgroud)

在我的单元测试中,我有:

 it('should ', inject([SomeService], (someService: SomeService) => {         
    let oldValue = someService.myValue;    
    expect(oldValue).toBe(false); // passes, clearly we can use our getter
    someService.myValue = true;    
    expect(someService.myValue).toBe(true); // passed, clearly the setter worked

    spyOnProperty(someService, 'myValue', 'getter').and.returnValue(false); // Property myValue does not have access type getter

    //spyOnProperty(someService, 'myValue', 'get').and.returnValue(false);same error if tried this way

    expect(someService.myValue).toBe(false); …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing jasmine karma-jasmine angular

16
推荐指数
2
解决办法
2万
查看次数

在熊猫中舍入到最接近的 1000

我已经搜索了 pandas 文档和食谱,很明显您可以使用dataframe.columnName.round(decimalplace).

你如何用更大的数字做到这一点?

例如,我有一列房价,我希望它们四舍五入到最接近的 10000 或 1000 或其他。

df.SalesPrice.WhatDoIDo(1000)? 
Run Code Online (Sandbox Code Playgroud)

python pandas data-science

8
推荐指数
1
解决办法
6828
查看次数