It appears that any assertion template functions that take an array of nodes can be mutated by calling setProperty. For example, setChildren takes an array of DNode children. setProperty modifies the node directly, and since the nodes from setChildren do not get recreated (because they are in an array and not some kind of function that returns them) the property changes persist.
Package Version: 5.0.5
Code
Unfortunately, codesandbox is erroring w/ this code so I can't just post a link, but this should reproduce the issue.
import { tsx } from "@dojo/framework/widget-core/tsx";
import assertionTemplate from "@dojo/framework/testing/assertionTemplate";
import harness from "@dojo/framework/testing/harness";
const baseAssertionTemplate = assertionTemplate(() => <div key="root" />);
const childAssertionTemplate = baseAssertionTemplate.setChildren("@root", [
<div key="child" title="original title" />
]);
const h = harness(() => (
<div key="root">
<div key="child" title="original title" />
</div>
));
h.expect(childAssertionTemplate);
h.expect(childAssertionTemplate.setProperty('@child', 'title', 'something else'));
h.expect(childAssertionTemplate);
Expected behavior:
I would expect the first expect to succeed, the second to fail, the third to succeed.
Actual behavior:
The third expect fails because node in childAssertionTemplate has been mutated.
It appears that any assertion template functions that take an array of nodes can be mutated by calling
setProperty. For example,setChildrentakes an array ofDNodechildren.setPropertymodifies the node directly, and since the nodes fromsetChildrendo not get recreated (because they are in an array and not some kind of function that returns them) the property changes persist.Package Version: 5.0.5
Code
Unfortunately, codesandbox is erroring w/ this code so I can't just post a link, but this should reproduce the issue.
Expected behavior:
I would expect the first
expectto succeed, the second to fail, the third to succeed.Actual behavior:
The third
expectfails because node inchildAssertionTemplatehas been mutated.