Cookbook
Copy-paste recipes for recurring test scenarios. All snippets assume import { should } from '@artstesh/it-should'; (plus Times where used).
A sorted API response
it('returns users ordered by age', () => {
const users = service.getUsers();
should().array(users).ordered({ by: (u) => u?.age });
});
A paginated list with a stable contract
it('returns exactly one page of active users', () => {
const page = service.getActiveUsers(1);
should().array(page).length(20)
.containOnly((u) => u!.active);
});
"This field, exactly twice"
import { should, Times } from '@artstesh/it-should';
it('mentions the disclaimer twice', () => {
should().string(body).contains('disclaimer', Times.twice());
});
Comparing DTOs with generated fields
it('maps the entity to the DTO', () => {
should()
.objects(actualDto, expectedDto)
.ignoring('updatedAt', 'version')
.equal();
});
The same data under different field names
should()
.objects(apiResponse, domainModel)
.map('first_name', 'firstName')
.map('last_name', 'lastName')
.equal();
A timestamp within a tolerance
it('stamps the event with the current time', () => {
should().date(event.timestamp).equals(new Date(), 'minute'); // same minute is enough
});
Unique keys in a collection
should().array(rows).uniq((r) => r?.id); // no duplicate ids
No forbidden calls recorded
it('does not touch analytics during logout', () => {
service.logout();
should().array(analyticsSpy.calls).not.containBy((c) => c!.name === 'page_view');
});
Presence and absence
should().string(cache.get('key')).defined(); // cached
should().string(cache.get('removed')).not.defined(); // evicted
More
Behavior quirks and sharp edges: Caveats.
Recommended habits: Best Practices.
Every signature: API reference.
02 сентября 2026