|
| 1 | +const parser = require('../../lib/parser'); |
| 2 | +const assert = require('assert'); |
| 3 | +const chai = require('chai'); |
| 4 | + |
| 5 | +const expect = chai.expect; |
| 6 | + |
| 7 | +class Obj { |
| 8 | + method1(locator, sec) {} |
| 9 | + method2(locator, value, sec) {} |
| 10 | + method3(locator, context) {} |
| 11 | + async method4(locator, context) { |
| 12 | + return false; |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +describe('parser', () => { |
| 17 | + const obj = new Obj(); |
| 18 | + |
| 19 | + describe('#getParamsToString', () => { |
| 20 | + it('should get params for normal function', () => { |
| 21 | + expect(parser.getParamsToString(obj.method1)).to.eql('locator, sec'); |
| 22 | + }); |
| 23 | + it('should get params for async function', () => { |
| 24 | + expect(parser.getParamsToString(obj.method4)).to.eql('locator, context'); |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + describe('#toTypeDef', () => { |
| 29 | + it('should transform function to TS types', () => { |
| 30 | + const res = parser.toTypeDef(obj.method1); |
| 31 | + expect(res).to.include(' method1(locator: ILocator, sec: number) : void'); |
| 32 | + expect(res).to.include(' method1(locator: string, sec: number) : void'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should transform function to TS types', () => { |
| 36 | + const res = parser.toTypeDef(obj.method2); |
| 37 | + expect(res).to.include('method2(locator: ILocator, value: string, sec: number) : void'); |
| 38 | + expect(res).to.include('method2(locator: string, value: string, sec: number) : void'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should transform function to TS types', () => { |
| 42 | + const res = parser.toTypeDef(obj.method3); |
| 43 | + expect(res).to.include('method3(locator: ILocator, context: ILocator) : void'); |
| 44 | + expect(res).to.include('method3(locator: ILocator, context: string) : void'); |
| 45 | + expect(res).to.include('method3(locator: string, context: ILocator) : void'); |
| 46 | + expect(res).to.include('method3(locator: string, context: string) : void'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should transform function to TS types', () => { |
| 50 | + const res = parser.toTypeDef(obj.method4); |
| 51 | + expect(res).to.include('method4(locator: ILocator, context: ILocator) : void'); |
| 52 | + expect(res).to.include('method4(locator: ILocator, context: string) : void'); |
| 53 | + expect(res).to.include('method4(locator: string, context: ILocator) : void'); |
| 54 | + expect(res).to.include('method4(locator: string, context: string) : void'); |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments