
The data returned by `Pattern.getRenderProps()` was not serializable as we were returning `this` all over the place, thereby including marcors, log methods, cyclic object references, and so on. This commit changes that by implementing a `.asRenderProp()` method on all of the various objects (stack, part, path, point, snippet, attributes, svg) and only including data that can be serialized. In addition, we no longer include the logs in the renderProps because they are not related to rendering the pattern. Instead, the new method `Pattern.getLogs()` gives you the logs.
30 lines
861 B
JavaScript
30 lines
861 B
JavaScript
import chai from 'chai'
|
|
import { Design } from '../src/index.mjs'
|
|
|
|
const expect = chai.expect
|
|
|
|
describe('Pattern Rendering', () => {
|
|
describe('Pattern.prototype.getRenderProps()', () => {
|
|
describe('Hidden parts and stacks', () => {
|
|
const part = {
|
|
name: 'test',
|
|
draft: ({ part }) => {
|
|
part.hide()
|
|
return part
|
|
},
|
|
}
|
|
|
|
const design = new Design({ parts: [part] })
|
|
const pattern = new design({}).draft()
|
|
const props = pattern.getRenderProps()
|
|
const logs = pattern.getLogs()
|
|
|
|
it('Should not include hidden stacks', () => {
|
|
expect(props.stacks).not.to.have.property('test')
|
|
})
|
|
it('Should log that it has skipped a hidden stack', () => {
|
|
expect(logs.pattern.info).to.include('Stack test is hidden. Skipping in render props.')
|
|
})
|
|
})
|
|
})
|
|
})
|