From b3eee204da42fbc061357daecc6b228bab3e1fae Mon Sep 17 00:00:00 2001 From: Trent Willis Date: Wed, 28 Feb 2018 22:08:19 -0800 Subject: [PATCH 1/2] Test: Add failing test for verifySteps passing reference to log --- test/main/assert/step.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/main/assert/step.js b/test/main/assert/step.js index 9468d7832..ea7bd5652 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.todo( "steps array should not be reset in logging function", function( assert ) { + const result = loggedAssertions[ "verification-assertion" ].actual; + assert.deepEqual( result, [ "step one", "step two" ] ); + } ); + +} ); From e124d2ffd7603b58bc2ef678331de0a174a2e405 Mon Sep 17 00:00:00 2001 From: Trent Willis Date: Wed, 28 Feb 2018 22:16:31 -0800 Subject: [PATCH 2/2] Assert: Clone actual steps array to avoid passing internal reference --- src/assert.js | 5 ++++- test/main/assert/step.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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 ea7bd5652..b22cd72fd 100644 --- a/test/main/assert/step.js +++ b/test/main/assert/step.js @@ -153,7 +153,7 @@ QUnit.module( "assert.verifySteps value reference", function() { assert.verifySteps( [ "step one", "step two" ], "verification-assertion" ); } ); - QUnit.todo( "steps array should not be reset in logging function", function( assert ) { + 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" ] ); } );