Skip to content

Instantly share code, notes, and snippets.

@giathinh910
Created January 11, 2024 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giathinh910/329b22fcd6d1a29c04e1fc6ad6f4370c to your computer and use it in GitHub Desktop.
Save giathinh910/329b22fcd6d1a29c04e1fc6ad6f4370c to your computer and use it in GitHub Desktop.
Jest Dayjs custom matchers
import { Dayjs, OpUnitType } from 'dayjs';
const isEqualTime = (expected: Dayjs, unit: OpUnitType = 'ms') => ({
$$typeof: Symbol.for('jest.asymmetricMatcher'),
asymmetricMatch: (actual: Dayjs) => expected.isSame(actual, unit),
toAsymmetricMatcher: () => 'Dayjs<' + expected.toISOString() + '>',
});
export default isEqualTime;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment