@comparaonline/test-helpers

Test helpers and mock utils for http/https requests

Usage no npm install needed!

<script type="module">
  import comparaonlineTestHelpers from 'https://cdn.skypack.dev/@comparaonline/test-helpers';
</script>

README

Test-helpers

Notes

  • describeRecording default config path is process.cwd() + /src/test/cassettes/
  • Overwrite default config should be done using setupFilesAfterEnv on jest.config.js

Configs

API

Config name type default
defaultPath string 'src/test/cassettes'
useProcessCwd boolean true
createPath boolean true

Overwrite

import { setConfig, ConfigName } from '@comparaonline/test-helpers';

setConfig(ConfigName.DefaultPath, 'src/test/cassettes');
setConfig(ConfigName.UseProcessCwd, true);
setConfig(ConfigName.CreatePath, true);

Examples

Using describeRecording

// my-test.test.ts
import { describeRecording } from '@comparaonline/test-helpers';

const CASSETTES_PATH = 'first-test';

describe('My test with mock', () => {
  describeRecording(
    'My http test',
    () => {
      it('Should connect with something http', async () => {
        // do something
      });
    },
    CASSETTES_PATH
  );

  // After the first this will create /src/test/cassettes/first-test/my-test.my-http-rest.json
});

Generate testServer const/function

import { testServerGenerator } from '@comparaonline/test-helpers';
import { router } from './event-server/router'; // Change this route to your event-server/router

export const testServer = testServerGenerator(router);