|
1 |
| -// These tests are run using the "npm run parseUnitTest" command in package.json |
| 1 | +/** |
| 2 | + * @author : Shahrukh Khan, Roseanne Demasco, Steve Canavan |
| 3 | + * @functionality : Implementing chai tests for throttle functionality |
| 4 | + * @changelog : ##WHOEVER CHANGES THE FILE, date, details |
| 5 | + * * */ |
2 | 6 |
|
3 | 7 | import { expect } from 'chai';
|
4 |
| -import 'mocha'; |
5 |
| -import 'path'; |
6 | 8 |
|
7 | 9 | const displayOutputMessage = require('../../src/modules/client/displayOutputMessage');
|
8 |
| -const getRootProjectDir = require('../../src/modules/client/getRootProjectDir'); |
9 |
| -const onSaveCb = require('../../src/modules/client/onSaveCb'); |
10 | 10 | const sendgRPCRequest = require('../../src/modules/client/sendgRPCRequest');
|
| 11 | +const throttle = require('../../src/modules/client/throttleOnSave'); |
11 | 12 |
|
12 | 13 | describe('Testing all functions', function () {
|
13 | 14 | describe('Testing displayOutputMessage', function () {
|
14 | 15 | it('should be a function', function () {
|
15 | 16 | expect(typeof displayOutputMessage).to.equal('function');
|
16 | 17 | });
|
17 |
| - it('should fail on uneven number of brackets', function () { |
18 |
| - const result = displayOutputMessage('{'); |
19 |
| - expect(result.toString()).to.equal('Error: The following character makes the gRPC request unbalanced: {\nThe portion of the gRPC request that ran before the unbalance was detected was:\n{\n\n'); |
| 18 | + }); |
| 19 | + describe('Testing sendgRPCRequest', function () { |
| 20 | + it('should be a function', function () { |
| 21 | + expect(typeof sendgRPCRequest).to.equal('function'); |
| 22 | + }); |
| 23 | + }); |
| 24 | + describe('Testing throttle', function () { |
| 25 | + it('should be a function', function () { |
| 26 | + expect(typeof throttle).to.equal('function'); |
| 27 | + }); |
| 28 | + const add = (num1: number, num2: number): number => num1 + num2; |
| 29 | + const throttledAdd = throttle(add, 1000); |
| 30 | + it('should return a function', function () { |
| 31 | + expect(typeof throttledAdd).to.equal('function'); |
20 | 32 | });
|
21 |
| - it('should fail on wrong brackets', function () { |
22 |
| - const result = displayOutputMessage('{)})'); |
23 |
| - expect(result.toString()).to.equal('Error: The following character makes the gRPC request unbalanced: {\nThe portion of the query that ran before the unbalance was detected was:\n{\n\n'); |
| 33 | + describe('Testing function returned (throttledAdd) from throttle', function () { |
| 34 | + it('should invoke add the first time', function () { |
| 35 | + const firstResult = throttledAdd(1, 2); |
| 36 | + expect(firstResult).not.to.equal(undefined); |
| 37 | + }); |
| 38 | + it('should return undefined if immediately invoked again', function () { |
| 39 | + const secondResult = throttledAdd(2, 3); |
| 40 | + expect(secondResult).to.equal(undefined); |
| 41 | + }); |
| 42 | + it('should invoke add after designated delay', function (done) { |
| 43 | + setTimeout(() => { |
| 44 | + try { |
| 45 | + const secondResult = throttledAdd(2, 3); |
| 46 | + expect(secondResult).not.to.equal(undefined); |
| 47 | + done(); |
| 48 | + } catch (e) { |
| 49 | + done(e); |
| 50 | + } |
| 51 | + }, 1001); |
| 52 | + }); |
24 | 53 | });
|
25 |
| - // describe('Testing getRootProjectDir', function () { |
26 |
| - // it('should be a function', function () { |
27 |
| - // expect(typeof getRootProjectDir).to.equal('function'); |
28 |
| - // }); |
29 |
| - // }); |
30 |
| - // describe('Testing onSaveCb', function () { |
31 |
| - // it('should be a function', function () { |
32 |
| - // expect(typeof onSaveCb).to.equal('function'); |
33 |
| - // }); |
34 |
| - // }); |
35 |
| - // describe('Testing sendgRPCRequest', function () { |
36 |
| - // it('should be a function', function () { |
37 |
| - // expect(typeof sendgRPCRequest).to.equal('function'); |
38 |
| - // // }); |
39 | 54 | });
|
40 | 55 | });
|
0 commit comments