我想用Jasmine测试我的角度应用程序.所以我创建了一些测试,其中大部分工作正常.但是,我的一个功能要求用户填写提示.测试无法填写此提示,因此我嘲笑他们spyOn(window,'prompt').and.returnValue('test')
.这有效,但只有一次.
当我添加两个组件(提示所在的函数)时,我希望spyOn
第一个提示结果为'test',第二个提示符为'test2'.我尝试这样做如下:
it 'should place the component as last object in the form', ->
spyOn(window, 'prompt').and.returnValue('test')
builder.addFormObject 'default', {component: 'test'}
spyOn(window, 'prompt').and.returnValue('test2')
builder.addFormObject 'default', {component: 'test2'}
expect(builder.forms['default'][0].name).toEqual('test')
Run Code Online (Sandbox Code Playgroud)
但这会产生以下错误:Error: prompt has already been spied upon
这是非常合乎逻辑的,但我不知道用spyOn返回的另一种方式.
所以,我想要的是:在第一个addFormObject之前,我想监视返回'test'的提示符.第二个addFormObject我想监视返回'test2'
我有一个名为mainList的列表.mainList中的每个项都包含另一个名为detailList的列表.
我想从mainList中选择detailList中的属性评估为true的项目.
我希望能起作用:
var list = mainList.Where(x => x.detailList.Where(y => y.property == true));
Run Code Online (Sandbox Code Playgroud)
这不起作用,它无法将detailList转换为bool.
所以我的问题是如何在mainList中选择项目,其中该项目在detailList中具有有效属性.