test-utils.ts 668 B

1234567891011121314151617181920212223
  1. export const E2E_TESTING_ENV_VARIABLE = 'isE2ETest';
  2. export function setTestEnvironment() {
  3. process.env[E2E_TESTING_ENV_VARIABLE] = '1';
  4. }
  5. export function isTestEnvironment() {
  6. return !!process.env[E2E_TESTING_ENV_VARIABLE];
  7. }
  8. /**
  9. * Helper method for creating tests which assert a given error message when the operation is attempted.
  10. */
  11. export function assertThrowsWithMessage(operation: () => Promise<any>, message: string) {
  12. return async () => {
  13. try {
  14. await operation();
  15. fail('Should have thrown');
  16. } catch (err) {
  17. expect(err.message).toEqual(expect.stringContaining(message));
  18. }
  19. };
  20. }