diff --git a/packages/classes/src/lib/utils/is-primitive-constructor.util.ts b/packages/classes/src/lib/utils/is-primitive-constructor.util.ts index 8aa4850d8..ec9285ca9 100644 --- a/packages/classes/src/lib/utils/is-primitive-constructor.util.ts +++ b/packages/classes/src/lib/utils/is-primitive-constructor.util.ts @@ -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 + ); } diff --git a/packages/integration-test/src/lib/with-classes/fixtures/models/doctor.ts b/packages/integration-test/src/lib/with-classes/fixtures/models/doctor.ts new file mode 100644 index 000000000..d8a75be92 --- /dev/null +++ b/packages/integration-test/src/lib/with-classes/fixtures/models/doctor.ts @@ -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[]; +} diff --git a/packages/integration-test/src/lib/with-classes/fixtures/profiles/doctor.profile.ts b/packages/integration-test/src/lib/with-classes/fixtures/profiles/doctor.profile.ts new file mode 100644 index 000000000..ffc802b7a --- /dev/null +++ b/packages/integration-test/src/lib/with-classes/fixtures/profiles/doctor.profile.ts @@ -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); +}; diff --git a/packages/integration-test/src/lib/with-classes/map.spec.ts b/packages/integration-test/src/lib/with-classes/map.spec.ts index 75365b34f..efb6fd23a 100644 --- a/packages/integration-test/src/lib/with-classes/map.spec.ts +++ b/packages/integration-test/src/lib/with-classes/map.spec.ts @@ -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 { @@ -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, @@ -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); + }); });