/
recorder.spec.ts
56 lines (42 loc) · 1.47 KB
/
recorder.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { verifyAllOptions } from '../src/validators';
import {mockSpawnProcess, URI, DESTINATION} from './test.helpers';
import Recorder, { RecorderValidationError } from '../src/recorder';
jest.mock('../src/validators');
beforeEach(() => {
jest.mocked(verifyAllOptions).mockReturnValue([]);
mockSpawnProcess();
});
test('should throw RecorderValidationError if validation failed', () => {
jest.mocked(verifyAllOptions).mockReturnValue([
'Any validation error message',
'One more validation error message',
]);
expect(() => new Recorder(URI, DESTINATION)).toThrowError(new RecorderValidationError('Options invalid', [
'Any validation error message',
'One more validation error message',
]));
});
describe('isRecording', () => {
test('should return true if process started', async () => {
const recorder = new Recorder(URI, DESTINATION)
.start();
// We have to wait next tick
await Promise.resolve(true);
const isRecording = recorder.isRecording();
expect(isRecording).toBe(true);
});
test('should return false if process not started', async () => {
const recorder = new Recorder(URI, DESTINATION);
// We have to wait next tick
await Promise.resolve(true);
const isRecording = recorder.isRecording();
expect(isRecording).toBe(false);
});
test('should return false if process started & then stopped', () => {
const isRecording = new Recorder(URI, DESTINATION)
.start()
.stop()
.isRecording();
expect(isRecording).toBe(false);
});
});