我正在尝试测试 onClick 但它们没有被使用道具调用:
这是 file.js 的一部分
handleSystemClick = () => {
// var message = All unsaved changes will be lost.`
confirmAlert({
title: 'Confirm Navigation',
message: ' All unsaved changes will be lost.',
childrenElement: () => <div></div>,
confirmLabel: 'Confirm',
cancelLabel: 'Cancel',
onConfirm: () => {this.setState({ toSystemEntitlments: true})},
onCancel: () => {},
})
}
handleCancelClick = () => {
window.history.back();
}
Run Code Online (Sandbox Code Playgroud)
这是 file.js 的 render 方法
render()
return(
<div className='add-edit-button' id= 'test1' onClick={() => {this.handleSystemClick()}}>System</div>
<div className='add-edit-button' onClick={() => {this.handleCancelClick()}}>Cancel</div>
<div …Run Code Online (Sandbox Code Playgroud) 我是 C# 单元测试的新手,必须测试该方法是否正常工作。
这是我到目前为止所拥有的:
public async Task<IHttpActionResult> Post(API_FIRM_LINK aPI_FIRM_LINK)
{
db.API_FIRM_LINK.Add(aPI_FIRM_LINK);
await db.SaveChangesAsync();
return Created(aPI_FIRM_LINK);
}
Run Code Online (Sandbox Code Playgroud)
测试方法:不确定我是否走在正确的道路上 如果有人可以根据我的测试提供示例
public async Task PostTest()
{
////Arrange
API_FIRM_LINKController controller = new API_FIRM_LINKController();
API_FIRM_LINK aPI_FIRM_LINK = null;
IHttpActionResult expectedResult = await controller.Post(aPI_FIRM_LINK);
//act
IHttpActionResult result = await controller.Post(API_FIRM_LINK, aPI_FIRM_LINK);
////Assert
IComparer<IHttpActionResult> comparer = new IHttpActionResultComparer();
// Assert.IsTrue(comparer.Equals(expectedResult, result));
Assert.IsNotNull(result);
Console.Write(result);
Run Code Online (Sandbox Code Playgroud)