Skip to content

Commit

Permalink
fix(classes): isPrimitiveConstructor also returns true for Array cons…
Browse files Browse the repository at this point in the history
…tructor

fix #249
  • Loading branch information
nartc committed Jan 28, 2021
1 parent fd4e705 commit c5d111d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
* @param {Function} value
*/
export function isPrimitiveConstructor(value: unknown): boolean {
return value === String || value === Number || value === Boolean;
return (
value === String || value === Number || value === Boolean || value === Array
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { AutoMap } from '@automapper/classes';

export class Doctor {
@AutoMap()
name: string;
@AutoMap()
titleTags: string[];
}

export class DoctorDto {
@AutoMap()
name: string;
@AutoMap()
titleTags: string[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { MappingProfile } from '@automapper/types';
import { Doctor, DoctorDto } from '../models/doctor';

export const doctorProfile: MappingProfile = (mapper) => {
mapper.createMap(Doctor, DoctorDto);
};
13 changes: 13 additions & 0 deletions packages/integration-test/src/lib/with-classes/map.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { assertVm } from '../assert-vm.spec';
import { setupClasses } from '../setup.spec';
import { Doctor, DoctorDto } from './fixtures/models/doctor';
import { User, UserVm } from './fixtures/models/user';
import { PascalUser, PascalUserVm } from './fixtures/models/user-pascal';
import {
Expand All @@ -12,6 +13,7 @@ import {
FOR_SHOULD_IGNORE_PASS_CONDITION,
pascalAvatarProfile,
} from './fixtures/profiles/avatar.profile';
import { doctorProfile } from './fixtures/profiles/doctor.profile';
import {
pascalUserProfileProfile,
userProfileProfile,
Expand Down Expand Up @@ -197,4 +199,15 @@ describe('Map - Non Flattening', () => {
const vm = mapper.map(pascalUser, PascalUserVm, PascalUser);
expect(vm).toBeTruthy();
});

it('should map doctor', () => {
mapper.addProfile(doctorProfile);
const doctor = new Doctor();
doctor.name = 'Chau';
doctor.titleTags = ['title', 'tags', 'blah'];

const dto = mapper.map(doctor, DoctorDto, Doctor);
expect(dto.name).toEqual(doctor.name);
expect(dto.titleTags).toEqual(doctor.titleTags);
});
});

0 comments on commit c5d111d

Please sign in to comment.