Iterables
toBeIterableOf(expected)
Also available as an asymmetric matcher: expect.iterableOf(expected).
Use .toBeIterableOf to assert that a value is an iterable where each item matches the expected value, using deep equality.
.toBeStrictIterableOf(expected) and expect.strictIterableOf(expected) are also available to use strict deep equality.
const array = [1, 1, 2, 3];
const set = new Set(array);
it("is an iterable of the expected values", () => {
expect(array).toBeIterableOf(expect.any(Number));
expect(set).toBeIterableOf(expect.any(Number));
});
toBeSequence(...sequence)
Also available as an asymmetric matcher: expect.sequenceMatching(...sequence).
Use .toBeSequence to assert that a value is an iterable with the exact sequence of values, using reference equality.
const array = [1, 1, 2, 3];
const set = new Set(array);
it("is an iterable with the exact sequence of values", () => {
expect(array).toBeSequence(1, 1, 2, 3);
expect(set).toBeSequence(1, 2, 3);
});
toEqualSequence(...sequence)
Also available as an asymmetric matcher: expect.sequenceOf(...sequence).
Use .toEqualSequence to assert that a value is an iterable with the exact sequence of values.
.toStrictEqualSequence(...sequence) and expect.strictSequenceOf(...sequence) are also available to use strict deep equality.
const array = [1, 1, 2, 3];
const set = new Set(array);
it("is an iterable with the exact sequence of values", () => {
expect(array).toEqualSequence(1, 1, 2, 3);
expect(set).toEqualSequence(1, 2, 3);
});
toSatisfySequence(...predicates)
Also available as an asymmetric matcher: expect.sequence(...predicates).
Use .toSatisfySequence to assert that a value is an iterable where each item satisfies the corresponding predicate.
const array = [1, 1, 2, 3];
const set = new Set(array);
it("is an iterable where each item satisfies the corresponding predicate", () => {
expect(array).toSatisfySequence(
(value) => value === 1,
(value) => value === 1,
(value) => value === 2,
(value) => value === 3,
);
expect(set).toSatisfySequence(
(value) => value === 1,
(value) => value === 2,
(value) => value === 3,
);
});
toContainSequence(...sequence)
Also available as an asymmetric matcher: expect.containingSequence(...sequence).
Use .toContainSequence to assert that a value is an iterable that contains the expected sequence of values, using reference equality.
const array = [1, 1, 2, 3];
const set = new Set(array);
it("is an iterable that contains the exact sequence of values", () => {
expect(array).toContainSequence(1, 2);
expect(set).toContainSequence(1, 2);
});
toContainEqualSequence(...sequence)
Also available as an asymmetric matcher: expect.containingEqualSequence(...sequence).
Use .toContainEqualSequence to assert that a value is an iterable that contains the expected sequence of values, using deep equality.
.toContainStrictEqualSequence(...sequence) and expect.containingStrictEqualSequence(...sequence) are also available to use strict deep equality.
const array = [1, 1, 2, 3];
const set = new Set(array);
it("is an iterable that contains the exact sequence of values", () => {
expect(array).toContainEqualSequence(1, 2);
expect(set).toContainEqualSequence(1, 2);
});
toContainSequenceSatisfying(...predicates)
Also available as an asymmetric matcher: expect.containingSequenceSatisfying(...predicates).
Use .toContainSequenceSatisfying to assert that a value is an iterable that contains the expected sequence of values, where each item satisfies the corresponding predicate.
const array = [1, 1, 2, 3];
const set = new Set(array);
it("is an iterable that contains the exact sequence of values", () => {
expect(array).toContainSequenceSatisfying(
(value) => value === 1,
(value) => value === 2,
);
expect(set).toContainSequenceSatisfying(
(value) => value === 1,
(value) => value === 2,
);
});