我正在测试一个Javascript函数,返回一个数字数组,看看返回的数组是否包含与包含预期输出的数组相同的元素:
expect(myArray).toEqual(expectedArray);
如果myArray和expectedArray只包含整数,则可以完美地工作,但如果由于浮点精度错误而至少存在一个浮点数,则会失败。 toBeCloseTo
似乎无法在数组上运行。
目前我正在做一个循环来进行成员检查:
for (var i = 0; i < myArray.length; i++) {
expect(myArray[i]).toBeCloseTo(expectedArray[i]);
}
...但是有更清洁的方法吗?如果测试由于某种原因而失败,则输出会因 hideous 错误消息而膨胀。
答案 0 :(得分:7)
以下代码应该回答您的问题:
@extends('header')
<div id="form-su" style="background-color: #d8b6ff" >
<h3 class="signuph"> Register </h3>
</div>
<form method="POST" action="{{ route('admin.register') }}">
<input type="hidden" name="_token" value="{!! csrf_token() !!}">
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
<div class="div-su {{ $errors->has('name') ? ' has-error' : '' }}">
<input class="signup-menu2{{ $errors->has('name') ? ' has-error' : '' }}" " type="text" name="name" value="{{ old('name') }}" placeholder=" Name.." required >
<input class="signup-menu2{{ $errors->has('email') ? ' has-error' : '' }}" " type="email" name="email" value="{{ old('email') }}" placeholder=" Email.." required >
</br>
<input class="signup-menu2{{ $errors->has('password') ? ' has-error' : '' }}" type="password" name="password" placeholder=" Password.." required >
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
</br>
<label> confirm password
<input class="signup-menu2 " type="password" name="password_confirmation" placeholder=" Confirm Password.." required >
</label>
@endif
</br>
<button class="signup-btn" type="submit" name="submit" value="submit"> Sign Up </button>
</form> </br>
<p class="forgotten-password" href=""> Forgotten password?</p> </br>
<p class="log-in-here" a href="">Log in here </p> </br>
</div>
</div>
</form>
</body>
</html>
答案 1 :(得分:0)
试试这个:
for (let i=0; i<returnedArray.length; i++){
if(expectedArray.indexOf(returnedArray[i]) === -1 ){
console.log("not a match")
break;
}else{
console.log("it's a match")
break;
}
}