@comparaonline/test-helpers
v1.2.1
Published
Test helpers and mock utils for http/https requests
Downloads
724
Maintainers
Keywords
Readme
Test-helpers
Notes
describeRecording
default config path isprocess.cwd()
+/src/test/cassettes/
- Overwrite default config should be done using
setupFilesAfterEnv
onjest.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);