expectedStrings = [
'abc',
'def',
'ghi'
]
stringToCheck = 'zyxabc'
Я хочу проверить, содержит ли stringToCheck одну из строк ожидаемых строк с помощью Jest.Я видел методы stringContained и arrayContained, но я не уверен, как мне составить, чтобы тест работал.
Я хотел бы использовать что-то близкое к этому примеру:
describe('stringMatching in arrayContaining', () => {
const expected = [
expect.stringMatching(/^Alic/),
expect.stringMatching(/^[BR]ob/),
];
it('matches even if received contains additional elements', () => {
expect(['Alicia', 'Roberto', 'Evelina']).toEqual(
expect.arrayContaining(expected),
);
});
it('does not match if received does not contain expected elements', () => {
expect(['Roberto', 'Evelina']).not.toEqual(
expect.arrayContaining(expected),
);
});
});