UNPKG

2.72 kBJavaScriptView Raw
1const { BlockOperation } = require('../src/BlockOperation');
2
3describe('BlockOperation', () => {
4
5 describe('function BlockOperation', function () {
6 test('should be defined', () => {
7 expect(BlockOperation).toBeDefined();
8 });
9
10 test('should be instantiated', () => {
11 const operation = new BlockOperation(1, () => {
12 return true;
13 });
14
15 expect(operation).toBeDefined();
16 });
17
18 test('inherits from Operation', () => {
19 const operation = new BlockOperation(1, () => {
20 return true;
21 });
22
23 expect(operation.__proto__.__proto__.constructor.name).toBe('Operation');
24 });
25
26 test('should be valid type', () => {
27 const operation = new BlockOperation(1, () => {
28 return true;
29 });
30
31 expect(operation.constructor.name).toBe('BlockOperation');
32 });
33 });
34
35 describe('function constructor', () => {
36 test('it should accept an ID if only a number if passed as first argument', () => {
37 const operation = new BlockOperation(1);
38 expect(operation.id).toBe(1);
39 });
40
41 test('it should accept the callback if only a function if passed as first argument', () => {
42 const runFunction = jest.fn(() => {
43 return true;
44 });
45
46 const operation = new BlockOperation(runFunction);
47 operation.start();
48
49 expect(operation.id).toBeDefined();
50 expect(runFunction).toHaveBeenCalled();
51 });
52
53 test('it should accept an ID and the callback as first and second arugments respectively', () => {
54 const runFunction = jest.fn(() => {
55 return true;
56 });
57
58 const operation = new BlockOperation(1, runFunction);
59 operation.start();
60
61 expect(operation.id).toEqual(1);
62 expect(runFunction).toHaveBeenCalled();
63 });
64
65 test('it should throw error if no parameters are passed in', (done) => {
66 try {
67 const operation = new BlockOperation();
68 fail('should have failed at this point');
69 } catch (e) {
70 done();
71 }
72 });
73 });
74
75 describe('function start', () => {
76 test('operation block to be called', () => {
77 const runFunction = jest.fn(() => {
78 return true;
79 });
80
81 const operation = new BlockOperation(1, runFunction);
82 operation.start();
83
84 expect(runFunction).toHaveBeenCalled();
85 });
86 })
87});
\No newline at end of file