TestCollection
TestCollection
은 스위트 또는 모듈 내의 최상위 스위트 및 테스트의 컬렉션을 나타냅니다. 또한 컬렉션을 순회하는 데 유용한 메서드를 제공합니다.
INFO
대부분의 메서드는 컬렉션의 모든 항목이 필요하지 않을 경우 성능 향상을 위해 배열 대신 이터레이터를 반환합니다. 배열로 작업하는 것을 선호한다면 이터레이터를 펼칠 수 있습니다: [...children.allSuites()]
.
또한 컬렉션 자체가 이터레이터라는 점에 유의하세요:
for (const child of module.children) {
console.log(child.type, child.name);
}
size
컬렉션에 포함된 최상위 테스트 및 스위트의 개수입니다.
WARNING
이 개수는 중첩된 스위트와 테스트는 포함하지 않고, 최상위 테스트와 스위트만 포함합니다.
at
function at(index: number): TestCase | TestSuite | undefined;
특정 인덱스에 위치한 테스트 또는 스위트를 반환합니다. 이 메서드는 음수 인덱스를 허용합니다.
array
function array(): (TestCase | TestSuite)[];
동일한 컬렉션을 배열 형태로 반환합니다. TaskCollection
구현에서 지원되지 않는 map
및 filter
와 같은 Array
메서드를 사용하고자 할 때 유용합니다.
allSuites
function allSuites(): Generator<TestSuite, undefined, void>;
이 컬렉션과 그 하위 항목에 포함된 모든 스위트를 필터링하여 반환합니다.
for (const suite of module.children.allSuites()) {
if (suite.errors().length) {
console.log('failed to collect', suite.errors());
}
}
allTests
function allTests(state?: TestState): Generator<TestCase, undefined, void>;
이 컬렉션과 그 하위 항목에 포함된 모든 테스트를 필터링하여 반환합니다.
for (const test of module.children.allTests()) {
if (test.result().state === 'pending') {
console.log('test', test.fullName, 'did not finish');
}
}
state
값을 전달하여 상태별로 테스트를 필터링할 수 있습니다.
tests
function tests(state?: TestState): Generator<TestCase, undefined, void>;
이 컬렉션에 직접 포함된 테스트만 필터링하여 반환합니다. state
값을 전달하여 상태별로 테스트를 필터링할 수 있습니다.
suites
function suites(): Generator<TestSuite, undefined, void>;
이 컬렉션에 직접 포함된 스위트만 필터링하여 반환합니다.