From 62ab887ada0cf55cb4ebe9c8df3e06b6f390a6fc Mon Sep 17 00:00:00 2001 From: Andrew Kemp Date: Fri, 6 Mar 2020 13:08:13 -0500 Subject: [PATCH] Better org of tests --- jest.config.js | 5 +- tests/decorators/exclude.spec.ts | 22 +++++++++ .../decorators/pluck.spec.ts | 47 +++++-------------- tsconfig.json | 2 +- 4 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 tests/decorators/exclude.spec.ts rename test/serde.spec.ts => tests/decorators/pluck.spec.ts (64%) diff --git a/jest.config.js b/jest.config.js index a6324f8..3cd1b50 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,8 @@ module.exports = { - roots: ['src'], + roots: ['tests'], + moduleNameMapper: { + 'src/(.*)': '/src/$1', + }, preset: 'ts-jest', testEnvironment: 'node', coverageReporters: [ diff --git a/tests/decorators/exclude.spec.ts b/tests/decorators/exclude.spec.ts new file mode 100644 index 0000000..1d48e4a --- /dev/null +++ b/tests/decorators/exclude.spec.ts @@ -0,0 +1,22 @@ +import 'reflect-metadata'; +import { Serde } from "src/serde"; +import { Exclude } from 'src/decorators'; + +class ExcludeTestModel extends Serde { + name: string; + date: Date; + description: string; + @Exclude() frontendField: string; +} + +describe('@Exclude() Decorator', () => { + it('should remove properties marked during serialize', () => { + const testModel = new ExcludeTestModel().deserialize({ + name: 'test model', + description: 'this is a test model', + frontendField: 'test field' + }); + const serializedModel = testModel.serialize(); + expect(serializedModel).toEqual({ name: 'test model', description: 'this is a test model' }); + }); +}); \ No newline at end of file diff --git a/test/serde.spec.ts b/tests/decorators/pluck.spec.ts similarity index 64% rename from test/serde.spec.ts rename to tests/decorators/pluck.spec.ts index e1a4193..69c3730 100644 --- a/test/serde.spec.ts +++ b/tests/decorators/pluck.spec.ts @@ -1,48 +1,28 @@ -import { Serde } from 'src/serde'; -import { Exclude, Pluck } from 'src/decorators'; - -class ExcludeTestModel extends Serde { - name: string; - date: Date; - description: string; - @Exclude() frontendField: string; -} +import 'reflect-metadata'; +import { Serde } from "src/serde"; +import { Pluck } from 'src/decorators'; class PluckArrayTestModel extends Serde { - name: string; - @Pluck(['id']) nestedProperties: { id: number, name: string }[]; + name: string; + @Pluck(['id']) nestedProperties: { id: number, name: string }[]; } class PluckArrayTestTwoModel extends Serde { - name: string; - @Pluck('id') nestedProperties: { id: number, name: string }[]; + name: string; + @Pluck('id') nestedProperties: { id: number, name: string }[]; } class PluckObjectTestModel extends Serde { - name: string; - @Pluck(['id']) nestedProperty: { id: number, name: string }; + name: string; + @Pluck(['id']) nestedProperty: { id: number, name: string }; } class PluckObjectTestTwoModel extends Serde { - name: string; - @Pluck('id') nestedProperty: { id: number, name: string }; + name: string; + @Pluck('id') nestedProperty: { id: number, name: string }; } -describe('Serde', () => { - - describe('@Exclude() decorator tests', () => { - it('should remove properties marked during serialize', () => { - const testModel = new ExcludeTestModel().deserialize({ - name: 'test model', - description: 'this is a test model', - frontendField: 'test field' - }); - const serializedModel = testModel.serialize(); - expect(serializedModel).toEqual({ name: 'test model', description: 'this is a test model' }); - }); - }); - - describe('@Pluck() decorator tests', () => { +describe('@Pluck() Decorator', () => { it('should pluck \'id\' (property: T[]) from marked property during serialize', () => { const testModel = new PluckArrayTestModel().deserialize({ name: 'test model', @@ -88,5 +68,4 @@ describe('Serde', () => { const serializedModel = testModel.serialize(); expect(serializedModel).toEqual({ name: 'test model', nestedProperty: 2 }); }); - }); -}); \ No newline at end of file + }); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 9d40c18..e69dd7c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,6 +22,6 @@ ] }, "include": [ - "src/**/*", "test/**/*" + "src/**/*", "tests/**/*" ] } \ No newline at end of file