在下面的代码中,我的测试用例按预期通过,但我使用 stryker 进行突变测试,handleError 函数在突变测试中幸存下来,所以我想通过测试是否调用 handleError 函数来杀死突变体。需要帮忙测试私有函数。
我试过 spyOn 但没有用
const orderBuilderSpy = jest.spyOn(orderBuilder, 'build')
const handleError = jest.fn()
expect(rderBuilderSpy).toHaveBeenCalledWith(handleError)
Run Code Online (Sandbox Code Playgroud)
const orderBuilderSpy = jest.spyOn(orderBuilder, 'build')
const handleError = jest.fn()
expect(rderBuilderSpy).toHaveBeenCalledWith(handleError)
Run Code Online (Sandbox Code Playgroud)
我正在尝试将一些数据插入 dynamodb,正如预期的那样,我得到了一个ConditionalCheckFailedException
. 因此,我试图仅针对该场景捕获该异常,除此之外,我想为所有其他错误抛出服务器错误。但是要添加类型,我无法ConditionalCheckFailedException
在 aws-sdk 中找到。
这就是我想要做的。
// where to import this from
try {
await AWS.putItem(params).promise()
} catch (e) {
if (e instanceof ConditionalCheckFailedException) { // unable to find this exception type in AWS SDK
throw new Error('create error')
} else {
throw new Error('server error')
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试通过单击发送按钮从多个单选按钮组发送所选单选按钮ID的列表,
我的问题: 我从后端获得选择单选按钮,然后我应该能够更改单选按钮并发送回后端.但是当我尝试更改单选按钮时,它无法正常工作.
我不明白的是: 如何处理on更改功能,通常在更改时我们可以更改状态但是要在加载时更改状态我们应该抓取值单选按钮.最后我被击中了,不知道如何前进.
这是线框和代码段:
function CardsList(props) {
const cards = props.cards;
return (
<div>
{cards.map((card, idx) => (
<div>
{card.cardName}
{
card.options.map((lo,idx) => (
<li key={idx}>
<input
className="default"
type="radio"
name={card.cardName}
checked={lo.selected}
/>))
}
<div>
))}
</div>
);
}
//array of cards coming from the backend
const cards = [
{cardName:'card1',options:[{radioName:'card1-radio1',selected:'true'},
{radioName:'card1-radio2',selected:'false'}]},
{cardName:'card2',options:[{radioName:'card2-radio1',selected:'true'},
{radioName:'card2-radio2',selected:'false'}]}
];
ReactDOM.render(
<CardsList cards={cards} />,
document.getElementById('root')
);
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="root"></div>
Run Code Online (Sandbox Code Playgroud)
I am getting this error because I am accidentally calling some method in my render method. As my application code is really big I'm unable to find out where is this coming from.
When I click on the index.js link in the console it is taking me to the following code.
This is what I found after doing some debugging(call stack), But it's not the exact full component code, as there are too many lines of code in the component …
我有一个子组件,它将 type 作为输入
子组件:
export enum PersonTypes {
MALE = 'male',
FEMALE = 'female'
}
@Component({
selector: 'app-child'
})
export class ChildComponent {
@Input() type: PersonTypes;
}
Run Code Online (Sandbox Code Playgroud)
父组件:
@Component({
selector: 'app-parent'
})
export class ParentComponent {
}
Run Code Online (Sandbox Code Playgroud)
在父组件视图模板中:
<div>
<app-child [type]="PersonTypes.MALE"></app-child>
<app-child [type]="PersonTypes.FEMALE"></app-child>
</div>
Run Code Online (Sandbox Code Playgroud)
那么,问题是如何在模板中传递不同的枚举值?我发现一个答案说我们需要在父组件中创建一个新变量,然后将该值分配给模板中的“type”,如下所示。
@Component({
selector: 'app-parent',
template:` <div>
<app-child [type]="malePerson"></app-child>
<app-child [type]="femalePerson"></app-child>
</div> `
})
export class ParentComponent {
malePerson = PersonTypes.MALE;
femalePerson = PersonTypes.FEMALE;
}
Run Code Online (Sandbox Code Playgroud)
对我来说,这是一个过度的解决方案,如果我们有 10 个枚举属性,我们最终创建 10 个局部变量并在模板中分配它们太多了。
有更好的解决方案吗?
javascript ×3
nestjs ×2
reactjs ×2
typescript ×2
angular ×1
ecmascript-6 ×1
enums ×1
html ×1
jestjs ×1
node.js ×1
react-router ×1
redux ×1