diff --git a/src/assert.js b/src/assert.js index a9b8bf13a..69e5fe685 100644 --- a/src/assert.js +++ b/src/assert.js @@ -44,7 +44,10 @@ class Assert { // Verifies the steps in a test match a given array of string values verifySteps( steps, message ) { - this.deepEqual( this.test.steps, steps, message ); + + // Since the steps array is just string values, we can clone with slice + const actualStepsClone = this.test.steps.slice(); + this.deepEqual( actualStepsClone, steps, message ); this.test.steps.length = 0; } diff --git a/test/main/assert/step.js b/test/main/assert/step.js index 9468d7832..b22cd72fd 100644 --- a/test/main/assert/step.js +++ b/test/main/assert/step.js @@ -132,3 +132,30 @@ QUnit.test( "errors if not called when `assert.step` is used", function( assert assert.equal( message, "Expected assert.verifySteps() to be called before end of test after using assert.step(). Unverified steps: one" ); }; } ); + +// Testing to ensure steps array is not passed by reference: https://github.com/qunitjs/qunit/issues/1266 +QUnit.module( "assert.verifySteps value reference", function() { + + var loggedAssertions = {}; + + QUnit.log( function( details ) { + + if ( details.message === "verification-assertion" ) { + loggedAssertions[ details.message ] = details; + } + + } ); + + QUnit.test( "passing test to see if steps array is passed by reference to logging function", function( assert ) { + assert.step( "step one" ); + assert.step( "step two" ); + + assert.verifySteps( [ "step one", "step two" ], "verification-assertion" ); + } ); + + QUnit.test( "steps array should not be reset in logging function", function( assert ) { + const result = loggedAssertions[ "verification-assertion" ].actual; + assert.deepEqual( result, [ "step one", "step two" ] ); + } ); + +} );