mirror of
https://github.com/google/blockly.git
synced 2026-01-11 02:47:09 +01:00
fix: variable events not deserializing properly (#6832)
This commit is contained in:
@@ -53,7 +53,7 @@ export class VarCreate extends VarBase {
|
||||
*/
|
||||
override toJson(): VarCreateJson {
|
||||
const json = super.toJson() as VarCreateJson;
|
||||
if (!this.varType) {
|
||||
if (this.varType === undefined) {
|
||||
throw new Error(
|
||||
'The var type is undefined. Either pass a variable to ' +
|
||||
'the constructor, or call fromJson');
|
||||
|
||||
@@ -48,7 +48,7 @@ export class VarDelete extends VarBase {
|
||||
*/
|
||||
override toJson(): VarDeleteJson {
|
||||
const json = super.toJson() as VarDeleteJson;
|
||||
if (!this.varType) {
|
||||
if (this.varType === undefined) {
|
||||
throw new Error(
|
||||
'The var type is undefined. Either pass a variable to ' +
|
||||
'the constructor, or call fromJson');
|
||||
|
||||
@@ -21,7 +21,18 @@ suite('Var Create Event', function() {
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
test('untyped variable events round-trip through JSON', function() {
|
||||
const varModel =
|
||||
new Blockly.VariableModel(this.workspace, 'name', '', 'id');
|
||||
const origEvent = new Blockly.Events.VarCreate(varModel);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
|
||||
test('typed variable events round-trip through JSON', function() {
|
||||
const varModel =
|
||||
new Blockly.VariableModel(this.workspace, 'name', 'type', 'id');
|
||||
const origEvent = new Blockly.Events.VarCreate(varModel);
|
||||
|
||||
@@ -20,7 +20,18 @@ suite('Var Delete Event', function() {
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
test('untyped variable events round-trip through JSON', function() {
|
||||
const varModel =
|
||||
new Blockly.VariableModel(this.workspace, 'name', '', 'id');
|
||||
const origEvent = new Blockly.Events.VarDelete(varModel);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
|
||||
test('typed variable events round-trip through JSON', function() {
|
||||
const varModel =
|
||||
new Blockly.VariableModel(this.workspace, 'name', 'type', 'id');
|
||||
const origEvent = new Blockly.Events.VarDelete(varModel);
|
||||
|
||||
Reference in New Issue
Block a user