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:
@@ -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]));
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user