Skip to content

Commit

Permalink
🎨: adjust spec comparison
Browse files Browse the repository at this point in the history
Due to upgrding chai, the comparison function that compares structs did not work any more since it started to compare prototypes as well. Wrapping the compared objects in JSON.parse/stringify seems to solve the issue.
  • Loading branch information
merryman committed Feb 7, 2025
1 parent 7ae0be2 commit 936bd22
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lively.morphic/tests/components-test.cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,18 @@ const c6 = ComponentDescriptor.for(() => component(c5, {
moduleId
});

function structCompare (a, b, message) {
expect(JSON.parse(JSON.stringify(a))).to.eql(JSON.parse(JSON.stringify(b)), message);
}

describe('spec based components', () => {
afterEach(() => {
detach(e2);
});

it('specs are always fully expanded', () => {
let alicePolicy = c2.stylePolicy.getSubSpecFor('alice');
expect(d3.stylePolicy.spec).to.eql({
structCompare(d3.stylePolicy.spec, {
name: 'd3',
fill: Color.cyan,
defaultViewModel: TestViewModel,
Expand All @@ -272,7 +276,7 @@ describe('spec based components', () => {

const fooPolicy = c3.stylePolicy.getSubSpecFor('foo');
alicePolicy = fooPolicy.getSubSpecFor('alice');
expect(c4.stylePolicy.spec).to.eql({
structCompare(c4.stylePolicy.spec, {
name: 'c4',
submorphs: [
new PolicyApplicator({
Expand Down Expand Up @@ -336,7 +340,7 @@ describe('spec based components', () => {
]
}));

const expectedBuildSpec = {
const expectedBuildSpec = JSON.parse(JSON.stringify({
name: 'e2',
master: internalSpec,
submorphs: [
Expand Down Expand Up @@ -380,9 +384,9 @@ describe('spec based components', () => {
},
{ name: 'bar', __wasAddedToDerived__: true }
]
};
expect(internalSpec.asBuildSpec()).to.eql(expectedBuildSpec, 'equals generated');
expect(e2.stylePolicy.asBuildSpec()).to.eql(expectedBuildSpec, 'equals defined');
}));
expect(JSON.parse(JSON.stringify(internalSpec.asBuildSpec()))).to.eql(JSON.parse(JSON.stringify(expectedBuildSpec)), 'equals generated');
expect(JSON.parse(JSON.stringify(e2.stylePolicy.asBuildSpec()))).to.eql(expectedBuildSpec, 'equals defined');

const pa = new PolicyApplicator({}, c3);
const bs = pa.asBuildSpec();
Expand Down Expand Up @@ -433,7 +437,7 @@ describe('spec based components', () => {
submorphs: [{ name: 'bob', fill: Color.green }]
}, e1);
p2.__wasAddedToDerived__ = true;
expect(e2.stylePolicy.synthesizeSubSpec('foo')).to.eql(p2);
expect(JSON.parse(JSON.stringify(e2.stylePolicy.synthesizeSubSpec('foo')))).to.eql(JSON.parse(JSON.stringify(p2)));
expect(sanitizeSpec(e3.stylePolicy.synthesizeSubSpec('alice'))).to.eql({
...sanitizeSpec(getDefaultValuesFor('text')),
fill: Color.black,
Expand Down Expand Up @@ -820,7 +824,7 @@ describe('components', () => {
});

expect(part(T1).get('bob').master.parent).to.eql(T1.stylePolicy.getSubSpecFor('bob'));
expect(part(T1).get('bob').master.parent.parent).not.to.be.defined;
expect(part(T1).get('bob').master.parent.parent).to.be.undefined;
});

it('includes added morphs into inline policies', () => {
Expand Down

0 comments on commit 936bd22

Please sign in to comment.