Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix TypeHelpers tests #802

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions test/helpers/TypeHelpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { TypeHelpers, ModelKind, getTypeFromMapping, TypeMapping } from '../../src/helpers';
import { CommonModel, ConstrainedAnyModel, ConstrainedArrayModel, ConstrainedBooleanModel, ConstrainedDictionaryModel, ConstrainedEnumModel, ConstrainedFloatModel, ConstrainedIntegerModel, ConstrainedMetaModel, ConstrainedObjectModel, ConstrainedReferenceModel, ConstrainedStringModel, ConstrainedTupleModel, ConstrainedUnionModel } from '../../src/models';
import { TestRenderer } from '../TestUtils/TestRenderers';

describe('TypeHelpers', () => {
describe('extractKind', () => {
Expand Down Expand Up @@ -57,8 +56,7 @@ describe('TypeHelpers', () => {
});
});
describe('getTypeFromMapping', () => {
const testRenderer = new TestRenderer();
const typeMapping: TypeMapping<TestRenderer> = {
const typeMapping: TypeMapping<any> = {
Object: jest.fn().mockReturnValue('test'),
Reference: jest.fn().mockReturnValue('test'),
Any: jest.fn().mockReturnValue('test'),
Expand All @@ -72,30 +70,35 @@ describe('TypeHelpers', () => {
Union: jest.fn().mockReturnValue('test'),
Dictionary: jest.fn().mockReturnValue('test')
};
class CustomConstrainedMetaModel extends ConstrainedMetaModel {
getNearestDependencies(): ConstrainedMetaModel[] {
throw new Error('Method not implemented.');
}
}
test('should return undefined with generic constrained model', () => {
const constrainedModel = new ConstrainedMetaModel('', undefined, '');
const constrainedModel = new CustomConstrainedMetaModel('', undefined, '');

const t = () => {
getTypeFromMapping(typeMapping, {constrainedModel, renderer: testRenderer});
getTypeFromMapping(typeMapping, {constrainedModel, options: {}});
};
expect(t).toThrow('Could not find type for model');
});
const modelsToCheck = [
new ConstrainedObjectModel('', undefined, '', {}),
new ConstrainedReferenceModel('', undefined, '', new ConstrainedMetaModel('', undefined, '')),
new ConstrainedReferenceModel('', undefined, '', new CustomConstrainedMetaModel('', undefined, '')),
new ConstrainedAnyModel('', undefined, ''),
new ConstrainedFloatModel('', undefined, ''),
new ConstrainedIntegerModel('', undefined, ''),
new ConstrainedStringModel('', undefined, ''),
new ConstrainedBooleanModel('', undefined, ''),
new ConstrainedTupleModel('', undefined, '', []),
new ConstrainedArrayModel('', undefined, '', new ConstrainedMetaModel('', undefined, '')),
new ConstrainedArrayModel('', undefined, '', new CustomConstrainedMetaModel('', undefined, '')),
new ConstrainedEnumModel('', undefined, '', []),
new ConstrainedUnionModel('', undefined, '', []),
new ConstrainedDictionaryModel('', undefined, '', new ConstrainedMetaModel('', undefined, ''), new ConstrainedMetaModel('', undefined, ''))
new ConstrainedDictionaryModel('', undefined, '', new CustomConstrainedMetaModel('', undefined, ''), new CustomConstrainedMetaModel('', undefined, ''))
];
test.each(modelsToCheck)('should return type from mapping', (constrainedModel: ConstrainedMetaModel) => {
const foundType = getTypeFromMapping(typeMapping, {constrainedModel, renderer: testRenderer});
const foundType = getTypeFromMapping(typeMapping, {constrainedModel, options: {}});
expect(foundType).toEqual('test');
});
});
Expand Down