function ComponentRenderTest::testJsLibraryAttachesCorrectly

Same name in this branch
  1. 10 core/modules/sdc/tests/src/FunctionalJavascript/ComponentRenderTest.php \Drupal\Tests\sdc\FunctionalJavascript\ComponentRenderTest::testJsLibraryAttachesCorrectly()
Same name in other branches
  1. 11.x core/modules/sdc/tests/src/FunctionalJavascript/ComponentRenderTest.php \Drupal\Tests\sdc\FunctionalJavascript\ComponentRenderTest::testJsLibraryAttachesCorrectly()
  2. 11.x core/tests/Drupal/FunctionalJavascriptTests/Components/ComponentRenderTest.php \Drupal\FunctionalJavascriptTests\Components\ComponentRenderTest::testJsLibraryAttachesCorrectly()

Tests that the correct libraries are put on the page using JS.

This also covers all the path translations necessary to produce the correct path to the assets.

File

core/tests/Drupal/FunctionalJavascriptTests/Components/ComponentRenderTest.php, line 50

Class

ComponentRenderTest
Tests the correct rendering of components.

Namespace

Drupal\FunctionalJavascriptTests\Components

Code

public function testJsLibraryAttachesCorrectly() : void {
    $build = [
        '#type' => 'inline_template',
        '#template' => "{{ include('sdc_test:my-button', {\n        text: 'Click'\n      }, with_context = false) }}",
    ];
    \Drupal::state()->set('sdc_test_component', $build);
    $this->drupalGet('sdc-test-component');
    $page = $this->getSession()
        ->getPage();
    $page->find('css', '[data-component-id="sdc_test:my-button"]')
        ->click();
    $this->assertSame('Click power (1)', $page->find('css', '[data-component-id="sdc_test:my-button"]')
        ->getText());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.