#cy.data()
// Get all data
cy.data(): Record<string, unknown>Read all graph-level data. Graph data is separate from element data. Binary serialization includes it; constructor loading restores it, while cy.add(buffer) leaves the destination graph's data unchanged.
Record<string, unknown>the graph's data object
Example
cy.data('title', 'Example graph');console.log(cy.data().title); // 'Example graph'#cy.data(key)
// Get data by key
cy.data(key: string): unknownRead one graph-level data value.
| Name | Description |
|---|---|
key: string | the application field to read or write |
unknownthe value, or undefined when the key is unset
Example
cy.data('title', 'Example graph');console.log(cy.data('title')); // 'Example graph'#cy.data(key, value)
// Set data by key
cy.data(key: string, value: unknown): thisWrite one graph-level data value. Writes emit a data event.
| Name | Description |
|---|---|
key: string | the application field to read or write |
value: unknown | the value to store |
thisthis core, for chaining
Example
const result = cy.data('title', 'Example graph');console.log(result === cy); // true#cy.data(patch)
// Set several data fields
cy.data(patch: Record<string, unknown>): thisMerge several graph-level data fields. Writes emit a data event.
| Name | Description |
|---|---|
patch: Record<string, unknown> | the fields to merge; other fields stay unchanged |
thisthis core, for chaining
Example
cy.data({ title: 'Example graph' });console.log(cy.data('title')); // 'Example graph'Also spelled cy.attr.