Enum .toJSON() to return type name as specified (#1811)

* Enum `.toJSON()` to return type name as specified

* Fix text compares
This commit is contained in:
Jaco Greeff
2020-02-06 10:48:33 +01:00
committed by GitHub
parent a5eb11e5f3
commit 6be25966d8
20 changed files with 2804 additions and 2802 deletions
+1 -1
View File
@@ -191,7 +191,7 @@ describe('Enum', (): void => {
testDecode('Uint8Array', Uint8Array.from([0]), 'foo');
testDecode('Uint8Array', Uint8Array.from([1]), 'bar');
testEncode('toJSON', 'bar');
testEncode('toJSON', 'Bar');
testEncode('toNumber', 1);
testEncode('toString', 'Bar');
testEncode('toU8a', Uint8Array.from([1]));
+1 -1
View File
@@ -266,7 +266,7 @@ export default class Enum extends Base<Codec> {
*/
public toJSON (): AnyJson {
return this._isBasic
? stringCamelCase(this.toString())
? this.type
: { [this.type]: this.raw.toJSON() };
}
@@ -47,7 +47,7 @@ describe('createType', (): void => {
it('allows creation of a Enum (simple)', (): void => {
expect(
createTypeUnsafe(registry, '{"_enum": ["A", "B", "C"]}', [1]).toJSON()
).toEqual('b');
).toEqual('B');
});
it('allows creation of a Enum (parametrised)', (): void => {