Skip to content

Commit

Permalink
test(ts): add type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornware committed Feb 1, 2023
1 parent 682700e commit 429bc12
Show file tree
Hide file tree
Showing 92 changed files with 1,800 additions and 35 deletions.
23 changes: 22 additions & 1 deletion .eslintrc.base.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,26 @@ const config = {
allowTemplateLiterals: true
}
],
'@typescript-eslint/sort-type-union-intersection-members': 2,
'@typescript-eslint/sort-type-constituents': [
2,
{
checkIntersections: true,
checkUnions: true,
groupOrder: [
'named',
'keyword',
'operator',
'literal',
'function',
'import',
'conditional',
'object',
'tuple',
'intersection',
'union'
]
}
],
'@typescript-eslint/triple-slash-reference': [
2,
{
Expand Down Expand Up @@ -1015,6 +1034,8 @@ const config = {
},
plugins: ['chai-expect', 'jest-formatting'],
rules: {
'@typescript-eslint/ban-types': 0,
'@typescript-eslint/consistent-indexed-object-style': 0,
'@typescript-eslint/no-base-to-string': 0,
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/no-unused-expressions': 0,
Expand Down
26 changes: 26 additions & 0 deletions __fixtures__/ordered-pair.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @file Fixtures - OrderedPair
* @module fixtures/OrderedPair
*/

/**
* Pair of numbers representing a single point on a two-dimensional grid.
*
* @see https://splashlearn.com/math-vocabulary/geometry/ordered-pair
*/
interface IOrderedPair {
x: number
y: number
}

/**
* Pair of numbers representing a single point on a two-dimensional grid.
*
* @see https://splashlearn.com/math-vocabulary/geometry/ordered-pair
*/
type TOrderedPair = {
x: number
y: number
}

export type { IOrderedPair, TOrderedPair }
38 changes: 38 additions & 0 deletions __fixtures__/person.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @file Fixtures - Person
* @module fixtures/Person
*/

/**
* Data model representing a person.
*
* @class
*/
class Person {
/**
* @public
* @instance
* @member {string} first_name - First name
*/
public first_name: string

/**
* @public
* @instance
* @member {string} last_name - Last name
*/
public last_name: string

/**
* Creates a new person.
*
* @param {string} first_name - First name
* @param {string} last_name - Last name
*/
constructor(first_name: string, last_name: string) {
this.first_name = first_name
this.last_name = last_name
}
}

export default Person
38 changes: 38 additions & 0 deletions src/enums/__tests__/app-env.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @file Type Tests - AppEnv
* @module tutils/enums/tests/unit-d/AppEnv
*/

import type TestSubject from '../app-env'

describe('unit-d:enums/AppEnv', () => {
it('should match [CI = "ci"]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('CI')
.toMatchTypeOf<'ci'>()
})

it('should match [DEV = "development"]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('DEV')
.toMatchTypeOf<'development'>()
})

it('should match [PROD = "production"]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('PROD')
.toMatchTypeOf<'production'>()
})

it('should match [STG = "staging"]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('STG')
.toMatchTypeOf<'staging'>()
})

it('should match [TEST = "test"]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('TEST')
.toMatchTypeOf<'test'>()
})
})
44 changes: 44 additions & 0 deletions src/enums/__tests__/bson-type-alias.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @file Type Tests - BsonTypeAlias
* @module tutils/enums/tests/unit-d/BsonTypeAlias
*/

import type TestSubject from '../bson-type-alias'

describe('unit-d:enums/BsonTypeAlias', () => {
it('should match [BOOL = "bool"]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('BOOL')
.toMatchTypeOf<'bool'>()
})

it('should match [DECIMAL = "decimal"]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('DECIMAL')
.toMatchTypeOf<'decimal'>()
})

it('should match [DOUBLE = "double"]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('DOUBLE')
.toMatchTypeOf<'double'>()
})

it('should match [INT = "int"]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('INT')
.toMatchTypeOf<'int'>()
})

it('should match [LONG = "long"]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('LONG')
.toMatchTypeOf<'long'>()
})

it('should match [REGEX = "regex"]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('REGEX')
.toMatchTypeOf<'regex'>()
})
})
40 changes: 40 additions & 0 deletions src/enums/__tests__/bson-type-code.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @file Type Tests - BsonTypeCode
* @module tutils/enums/tests/unit-d/BsonTypeCode
*/

import type TestSubject from '../bson-type-code'

describe('unit-d:enums/BsonTypeCode', () => {
it('should match [BOOL = 8]', () => {
expectTypeOf<typeof TestSubject>().toHaveProperty('BOOL').toEqualTypeOf<8>()
})

it('should match [DECIMAL = 19]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('DECIMAL')
.toEqualTypeOf<19>()
})

it('should match [DOUBLE = 1]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('DOUBLE')
.toEqualTypeOf<1>()
})

it('should match [INT = 16]', () => {
expectTypeOf<typeof TestSubject>().toHaveProperty('INT').toEqualTypeOf<16>()
})

it('should match [LONG = 18]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('LONG')
.toEqualTypeOf<18>()
})

it('should match [REGEX = 11]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('REGEX')
.toEqualTypeOf<11>()
})
})
26 changes: 26 additions & 0 deletions src/enums/__tests__/compare-result.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @file Type Tests - CompareResult
* @module tutils/enums/tests/unit-d/CompareResult
*/

import type TestSubject from '../compare-result'

describe('unit-d:enums/CompareResult', () => {
it('should match [EQUAL = 8]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('EQUAL')
.toEqualTypeOf<0>()
})

it('should match [GREATER_THAN = 1]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('GREATER_THAN')
.toEqualTypeOf<1>()
})

it('should match [LESS_THAN = -1]', () => {
expectTypeOf<typeof TestSubject>()
.toHaveProperty('LESS_THAN')
.toEqualTypeOf<-1>()
})
})
Loading

0 comments on commit 429bc12

Please sign in to comment.