4
이 포함되어 있는지 확인? 아무거나 같이Should.js는 : 두 배열 내가 두 배열이 같은 문자열
should(a).be.xyz(b)
그들을 테스트 할 수 있습니까? 여기서, xyz는 제가 찾고있는 것입니다.
이 포함되어 있는지 확인? 아무거나 같이Should.js는 : 두 배열 내가 두 배열이 같은 문자열
should(a).be.xyz(b)
그들을 테스트 할 수 있습니까? 여기서, xyz는 제가 찾고있는 것입니다.
순진하지만 가능성이 충분한 솔루션을 비교하기 전에 배열을 정렬하는 것 :
should(a.sort()).be.eql(b.sort())
주 sort()
works in-place 즉, 원래의 배열을 돌연변이.
should
의 Assertion.add
기능으로 구현할 수 있습니다. 예 :
var a = ['a', 'as', 'sa'];
var b = ['sa', 'a', 'as'];
should.Assertion.add('haveSameItems', function(other) {
this.params = { operator: 'to be have same items' };
this.obj.forEach(item => {
//both arrays should at least contain the same items
other.should.containEql(item);
});
// both arrays need to have the same number of items
this.obj.length.should.be.equal(other.length);
});
//passes
a.should.haveSameItems(b);
b.push('d');
// now it fails
a.should.haveSameItems(b);
이 답변은 정확하지 않습니다. .equal은 참조 동등성을 위해 ===를 사용합니다. .eql을 사용해야합니다. –
@denbardadym 메모 주셔서 감사합니다, 내 대답을 업데이 트되었습니다. – Timo