File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -100,11 +100,11 @@ public static function useWebpack(): void
100
100
* @param array $attributes
101
101
* @return \Illuminate\Support\HtmlString
102
102
*/
103
- public function scripts (string $ script = null , array $ attributes = [' type ' => ' text/javascript ' ]): HtmlString
103
+ public function scripts (string $ script = null , array $ attributes = []): HtmlString
104
104
{
105
105
$ script = $ script ?: $ this ->generateScripts ();
106
106
$ attributes = $ this ->html ->attributes (
107
- array_merge ($ attributes , ['type ' => static ::$ jsType ])
107
+ array_merge ($ attributes , ['type ' => $ attributes [ ' type ' ] ?? static ::$ jsType ])
108
108
);
109
109
110
110
return new HtmlString ("<script {$ attributes }> $ script</script> " );
Original file line number Diff line number Diff line change 11
11
12
12
class BuilderTest extends TestCase
13
13
{
14
+ /** @test */
15
+ public function it_can_get_script_default_type_attribute ()
16
+ {
17
+ $ html = $ this ->getHtmlBuilder ()->scripts ()->toHtml ();
18
+
19
+ $ this ->assertStringContainsString ('type="text/javascript" ' , $ html );
20
+ }
21
+
22
+ /** @test */
23
+ public function it_can_set_script_type_attribute ()
24
+ {
25
+ $ html = $ this ->getHtmlBuilder ()->scripts (attributes: ['type ' => 'module ' ])->toHtml ();
26
+
27
+ $ this ->assertStringContainsString ('type="module" ' , $ html );
28
+ }
29
+
30
+ /** @test */
31
+ public function it_can_set_multiple_script_attributes ()
32
+ {
33
+ $ html = $ this ->getHtmlBuilder ()->scripts (attributes: ['prop1 ' => 'val1 ' , 'prop2 ' => 'val2 ' ])->toHtml ();
34
+
35
+ $ this ->assertStringContainsString ('prop1="val1" ' , $ html );
36
+ $ this ->assertStringContainsString ('prop2="val2" ' , $ html );
37
+ }
38
+
14
39
/** @test */
15
40
public function it_can_use_vitejs_module_script ()
16
41
{
You can’t perform that action at this time.
0 commit comments