three-nebula
three-nebula copied to clipboard
`preset` object of particles will be changed in test case
Expected behavior
preset
object will not be changed in the test.
Actual behavior
Vector3D objects in preset
object will be changed in the test.
How to reproduce
Output preset
before and after particle.reset()
.
https://github.com/creativelifeform/three-nebula/blob/7e0b2dc9afefc4838a22475d6cca91e513ad9812/test/core/Particle.spec.js#L112-L115
it("should reset the particle's clearable properties and return the particle", done => {
const particle = new Particle(preset);
console.log(preset); // <- velocity: Vector3D { x: 1, y: 2, z: 2 }
const reset = particle.reset();
console.log(preset); // <- velocity: Vector3D { x: 0, y: 0, z: 0 }
Impact
Currently this issue does not affect us, but it may damage our tests in the future.
Cause
https://github.com/creativelifeform/three-nebula/blob/7e0b2dc9afefc4838a22475d6cca91e513ad9812/src/core/Particle.js#L232-L237
Particle instances and preset
share the same Vector3D object. Vector3D.set()
impacts preset
.
Suggestion
https://github.com/creativelifeform/three-nebula/blob/7e0b2dc9afefc4838a22475d6cca91e513ad9812/test/core/fixtures/particle.js#L4
Change preset
object to getPreset()
function.
If the preset object is instantiated for each test cases, the impact will not go over the test case.