-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(): Support easy serialization of custom properties (#10071)
- Loading branch information
Showing
3 changed files
with
196 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { FabricObject } from './FabricObject'; | ||
|
||
describe('FabricObject toObject', () => { | ||
test('without custom properties', () => { | ||
const obj = new FabricObject({ name: 'test1', key2: 'value2' }); | ||
expect(obj.name).toBe('test1'); | ||
expect(obj.key2).toBe('value2'); | ||
const serialized = obj.toObject(); | ||
expect(serialized.name).toBe(undefined); | ||
expect(serialized.key2).toBe(undefined); | ||
}); | ||
test('with custom properties', () => { | ||
const obj = new FabricObject({ name: 'test1', key2: 'value2' }); | ||
expect(obj.name).toBe('test1'); | ||
expect(obj.key2).toBe('value2'); | ||
const serialized = obj.toObject(['name']); | ||
expect(serialized.name).toBe('test1'); | ||
expect(serialized.key2).toBe(undefined); | ||
}); | ||
test('with default custom properties', () => { | ||
FabricObject.customProperties = ['key2']; | ||
const obj = new FabricObject({ name: 'test1', key2: 'value2' }); | ||
expect(obj.name).toBe('test1'); | ||
expect(obj.key2).toBe('value2'); | ||
const serialized = obj.toObject(); | ||
expect(serialized.name).toBe(undefined); | ||
expect(serialized.key2).toBe('value2'); | ||
}); | ||
test('with both custom properties', () => { | ||
FabricObject.customProperties = ['key2']; | ||
const obj = new FabricObject({ name: 'test1', key2: 'value2' }); | ||
expect(obj.name).toBe('test1'); | ||
expect(obj.key2).toBe('value2'); | ||
const serialized = obj.toObject(['name']); | ||
expect(serialized.name).toBe('test1'); | ||
expect(serialized.key2).toBe('value2'); | ||
}); | ||
test('customProperties gets cloned', async () => { | ||
FabricObject.customProperties = ['key2', 'name']; | ||
const obj = new FabricObject({ name: 'test1', key2: 'value2' }); | ||
expect(obj.name).toBe('test1'); | ||
expect(obj.key2).toBe('value2'); | ||
const clone = await obj.clone(); | ||
expect(clone.name).toBe('test1'); | ||
expect(clone.key2).toBe('value2'); | ||
}); | ||
}); |