Skip to content

Commit

Permalink
Fixes jest serializer output for GhostExome
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcisbee committed May 13, 2021
1 parent 7a445b0 commit a23a2fa
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.10.1

* Fixes jest serializer output for `GhostExome`;

## 0.10.0

* Adds `GhostExome` class;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "exome",
"version": "0.10.0",
"version": "0.10.1",
"description": "Proxy based store manager for deeply nested states",
"main": "exome.js",
"module": "exome.esm.js",
Expand Down
77 changes: 77 additions & 0 deletions src/jest/serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { test } from 'uvu'
import assert from 'uvu/assert'

import { Exome } from '../exome'
import { GhostExome } from '../ghost-exome'

const {
print,
test: testSerializer
} = proxyquire('./serializer.ts', {
exome: {
Exome,
GhostExome,
'@noCallThru': true
}
})
Expand All @@ -36,19 +38,38 @@ test('`test` returns `true` when encountering instance of Exome', () => {
assert.is(output, true)
})

test('`test` returns `true` when encountering instance of GhostExome', () => {
const output = testSerializer(new GhostExome())

assert.is(output, true)
})

test('`test` returns `true` when encountering instance of extended Exome', () => {
class Extended extends Exome {}
const output = testSerializer(new Extended())

assert.is(output, true)
})

test('`test` returns `true` when encountering instance of extended GhostExome', () => {
class Extended extends GhostExome {}
const output = testSerializer(new Extended())

assert.is(output, true)
})

test('`test` returns `false` when encountering `Exome`', () => {
const output = testSerializer(Exome)

assert.is(output, false)
})

test('`test` returns `false` when encountering `GhostExome`', () => {
const output = testSerializer(GhostExome)

assert.is(output, false)
})

test('`test` returns `false` when encountering `undefined`', () => {
const output = testSerializer(undefined)

Expand Down Expand Up @@ -153,6 +174,62 @@ test('`print` outputs nested extended Exome instance', () => {
}`)
})

test('`print` outputs empty GhostExome instance', () => {
const output = print(new GhostExome())

assert.snapshot(output, 'GhostExome {}')
})

test('`print` outputs empty extended GhostExome instance', () => {
class Extended extends GhostExome { }
const output = print(new Extended())

assert.snapshot(output, 'Extended {}')
})

test('`print` outputs filled extended GhostExome instance', () => {
class Extended extends GhostExome {
public name?: string
public foo = 'bar'

public get gotName() {
return 'this will not show'
}

public methodFoo() {}
private methodBar() {}
}
const output = print(new Extended())

assert.snapshot(output, `Extended {
"foo": "bar"
}`)
})

test('`print` outputs nested extended GhostExome instance', () => {
class Dog extends GhostExome {
constructor(
public name: string
) {
super()
}
}
class Owner extends GhostExome {
public dogs = [
new Dog('Andy')
]
}
const output = print(new Owner())

assert.snapshot(output, `Owner {
"dogs": [
{
"name": "Andy"
}
]
}`)
})

test('`print` outputs untitled class', () => {
const output = print(new (class {})())

Expand Down
6 changes: 3 additions & 3 deletions src/jest/serializer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Exome } from 'exome'
import { Exome, GhostExome } from 'exome'

export function test(val: any): boolean {
return val instanceof Exome
return val instanceof Exome || val instanceof GhostExome
}

export function print(val: typeof Exome): string {
const proto: Exome = Object.getPrototypeOf(val)
const proto: Exome | GhostExome = Object.getPrototypeOf(val)
const name: string = proto.constructor.name || ''

return `${name} ${JSON.stringify(val, null, ' ')}`
Expand Down

0 comments on commit a23a2fa

Please sign in to comment.