-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(test): Add feature-gated and matrix based unit testing in CI
- Loading branch information
1 parent
7469bbd
commit a06ff79
Showing
6 changed files
with
114 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
test/transformer/descriptor/methods/feature.overloads.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { createMock } from 'ts-auto-mock'; | ||
|
||
import { | ||
exportedDeclaredOverloadedFunction, | ||
ExportedDeclaredClass, | ||
} from '../utils/typeQuery/typeQueryUtils'; | ||
|
||
const isFeatureEnabled: boolean = process.env.FEATURE === 'transformOverloads'; | ||
|
||
describe('feature', () => { | ||
|
||
describe('for overloads', () => { | ||
|
||
describe('for type query', () => { | ||
|
||
it('should assign the correct function mock for literal inputs', () => { | ||
const functionMock: typeof exportedDeclaredOverloadedFunction = createMock<typeof exportedDeclaredOverloadedFunction>(); | ||
|
||
// eslint-disable-next-line | ||
const expectations = [ | ||
['', 0, false], | ||
[false, '', 0], | ||
[0, false, ''], | ||
[false, false, false], | ||
[''], | ||
[false], | ||
[0], | ||
]; | ||
|
||
for (const args of expectations) { | ||
// eslint-disable-next-line | ||
const [first] = args; | ||
|
||
// @ts-ignore | ||
expect(functionMock(...args)).toEqual(isFeatureEnabled ? first : false); | ||
} | ||
}); | ||
|
||
it('should assign the correct function mock for mockable inputs', () => { | ||
const classMock: typeof ExportedDeclaredClass = createMock<typeof ExportedDeclaredClass>(); | ||
|
||
const functionMock: typeof exportedDeclaredOverloadedFunction = createMock<typeof exportedDeclaredOverloadedFunction>(); | ||
|
||
if (isFeatureEnabled) { | ||
expect(functionMock(new classMock()).prop).toBe(0); | ||
} else { | ||
expect(functionMock(new classMock()).prop).toBeUndefined(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
describe('for interface', () => { | ||
describe('for construct signature', () => { | ||
interface InterfaceWithConstructSignatureOverload { | ||
new (a: number): { a: number }; | ||
new (b: string): { b: string }; | ||
new (): { c: Date }; | ||
} | ||
|
||
it('should use the correct signature as requested by input', () => { | ||
const properties: InterfaceWithConstructSignatureOverload = createMock<InterfaceWithConstructSignatureOverload>(); | ||
|
||
expect((new properties(0)).a).toBe(0); | ||
|
||
if (isFeatureEnabled) { | ||
expect((new properties('')).b).toBe(''); | ||
expect((new properties()).c).toBeInstanceOf(Date); | ||
} else { | ||
expect((new properties('')).b).toBeUndefined(); | ||
expect((new properties()).c).toBeUndefined(); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe('call signature', () => { | ||
interface InterfaceWithCallSignature { | ||
(a: number): number; | ||
(a: string): string; | ||
b: string; | ||
} | ||
|
||
it('should consider all signature declarations and properties', () => { | ||
const properties: InterfaceWithCallSignature = createMock<InterfaceWithCallSignature>(); | ||
|
||
expect(properties.b).toBe(''); | ||
expect(properties(2)).toBe(0); | ||
|
||
if (isFeatureEnabled) { | ||
expect(properties('2')).toBe(''); | ||
} else { | ||
// @ts-ignore | ||
expect(properties('2')).toBe(0); | ||
} | ||
}); | ||
}); | ||
|
||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters