diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php
index 667f705..3f94db8 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -1586,6 +1586,8 @@ protected function drupalPostForm($path, $edit, $submit, array $options = array(
     $ajax = is_array($submit);
     if (isset($path)) {
       $this->drupalGet($path, $options);
+    } else {
+      $path = $this->getUrl();
     }
 
     if ($this->parse()) {
diff --git a/core/modules/system/src/Tests/Ajax/CommandsTest.php b/core/modules/system/src/Tests/Ajax/CommandsTest.php
index 636c769..6acd30d 100644
--- a/core/modules/system/src/Tests/Ajax/CommandsTest.php
+++ b/core/modules/system/src/Tests/Ajax/CommandsTest.php
@@ -21,6 +21,7 @@
 use Drupal\Core\Ajax\InsertCommand;
 use Drupal\Core\Ajax\PrependCommand;
 use Drupal\Core\Ajax\RemoveCommand;
+use Drupal\Core\Ajax\ReplaceCommand;
 use Drupal\Core\Ajax\RestripeCommand;
 use Drupal\Core\Ajax\SettingsCommand;
 use Drupal\Core\EventSubscriber\AjaxResponseSubscriber;
@@ -99,6 +100,11 @@ function testAjaxCommands() {
     $expected = new InsertCommand('#insert_div', 'insert replacement text');
     $this->assertCommand($commands, $expected->render(), "'insert' AJAX command issued with correct data.");
 
+    // Tests the 'replace' command.
+    $commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX insert: Let client replace based on #ajax['method'].")));
+    $expected = new ReplaceCommand('#replace_div', 'replace_div replacement text');
+    $this->assertCommand($commands, $expected->render(), "'replace' AJAX command issued with correct data.");
+
     // Tests the 'invoke' command.
     $commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX invoke command: Invoke addClass() method.")));
     $expected = new InvokeCommand('#invoke_div', 'addClass', array('error'));
diff --git a/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
index 3e47088..cd10e92 100644
--- a/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
+++ b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
@@ -117,6 +117,15 @@ function ajax_forms_test_advanced_commands_insert_callback($form, FormStateInter
 }
 
 /**
+ * Ajax form callback: Selects 'replace'.
+ */
+function ajax_forms_test_advanced_commands_replace_callback($form, FormStateInterface $form_state) {
+  $response = new AjaxResponse();
+  $response->addCommand(new Ajax\ReplaceCommand('#replace_div', 'replace_div replacement text'));
+  return $response;
+}
+
+/**
  * Ajax form callback: Selects 'prepend'.
  */
 function ajax_forms_test_advanced_commands_prepend_callback($form, FormStateInterface $form_state) {
diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestCommandsForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestCommandsForm.php
index e708d92..43d2652 100644
--- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestCommandsForm.php
+++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestCommandsForm.php
@@ -139,6 +139,17 @@ public function buildForm(array $form, FormStateInterface $form_state) {
       '#suffix' => '<div id="insert_div">Original contents</div>',
     );
 
+    // Shows the Ajax 'replace' command.
+    $form['replace_command_example'] = array(
+      '#value' => $this->t("AJAX insert: Let client replace based on #ajax['method']."),
+      '#type' => 'submit',
+      '#ajax' => array(
+        'callback' => 'ajax_forms_test_advanced_commands_replace_callback',
+        'method' => 'prepend',
+      ),
+      '#suffix' => '<div id="replace_div">Original contents</div>',
+    );
+
     // Shows the Ajax 'prepend' command.
     $form['prepend_command_example'] = array(
       '#value' => $this->t("AJAX 'prepend': Click to prepend something"),
