|
13 | 13 | })
|
14 | 14 | ->with([
|
15 | 15 | 'an array' => [
|
16 |
| - 'parameter' => ['key' => 'value'], |
17 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'key\'] = \'value\';</script>', |
| 16 | + ['key' => 'value'], |
| 17 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'key\'] = \'value\';</script>', |
18 | 18 | ],
|
19 | 19 | 'a boolean with value of `true`' => [
|
20 |
| - 'parameter' => ['boolean' => true], |
21 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'boolean\'] = true;</script>', |
| 20 | + ['boolean' => true], |
| 21 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'boolean\'] = true;</script>', |
22 | 22 | ],
|
23 | 23 | 'a boolean with value of `false`' => [
|
24 |
| - 'parameter' => ['boolean' => false], |
25 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'boolean\'] = false;</script>', |
| 24 | + ['boolean' => false], |
| 25 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'boolean\'] = false;</script>', |
26 | 26 | ],
|
27 | 27 | 'an integer' => [
|
28 |
| - 'parameter' => ['number' => 5], |
29 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'number\'] = 5;</script>', |
| 28 | + ['number' => 5], |
| 29 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'number\'] = 5;</script>', |
30 | 30 | ],
|
31 | 31 | 'an float' => [
|
32 |
| - 'parameter' => ['number' => 5.5], |
33 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'number\'] = 5.5;</script>', |
| 32 | + ['number' => 5.5], |
| 33 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'number\'] = 5.5;</script>', |
34 | 34 | ],
|
35 | 35 | 'null' => [
|
36 |
| - 'parameter' => ['nothing' => null], |
37 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'nothing\'] = null;</script>', |
| 36 | + ['nothing' => null], |
| 37 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'nothing\'] = null;</script>', |
38 | 38 | ],
|
39 | 39 | 'a string with line breaks' => [
|
40 |
| - 'parameter' => ['string' => "This is\r\n a test"], |
41 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'string\'] = \'This is\\r\\n a test\';</script>', |
| 40 | + ['string' => "This is\r\n a test"], |
| 41 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'string\'] = \'This is\\r\\n a test\';</script>', |
42 | 42 | ],
|
43 | 43 | 'a numeric string as a string' => [
|
44 |
| - 'parameter' => ['socialSecurity' => '123456789'], |
45 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'socialSecurity\'] = \'123456789\';</script>', |
| 44 | + ['socialSecurity' => '123456789'], |
| 45 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'socialSecurity\'] = \'123456789\';</script>', |
46 | 46 | ],
|
47 | 47 | 'escapes tags in a string' => [
|
48 |
| - 'parameter' => ['string' => "This is a <tag>"], |
49 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'string\'] = \'This is a \<tag\>\';</script>', |
| 48 | + ['string' => "This is a <tag>"], |
| 49 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'string\'] = \'This is a \<tag\>\';</script>', |
50 | 50 | ],
|
51 | 51 | 'arrayable objects' => [
|
52 |
| - 'parameter' => new class () implements Arrayable { |
| 52 | + new class () implements Arrayable { |
53 | 53 | public function toArray()
|
54 | 54 | {
|
55 | 55 | return ['arrayableKey' => 'arrayableValue'];
|
56 | 56 | }
|
57 | 57 | },
|
58 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'arrayableKey\'] = \'arrayableValue\';</script>', |
| 58 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'arrayableKey\'] = \'arrayableValue\';</script>', |
59 | 59 | ],
|
60 | 60 | 'JSON serializable objects' => [
|
61 |
| - 'parameter' => new class () implements JsonSerializable { |
| 61 | + new class () implements JsonSerializable { |
62 | 62 | public function jsonSerialize()
|
63 | 63 | {
|
64 | 64 | return ['jsonKey' => 'jsonValue'];
|
65 | 65 | }
|
66 | 66 | },
|
67 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'0\'] = {"jsonKey":"jsonValue"};</script>', |
| 67 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'0\'] = {"jsonKey":"jsonValue"};</script>', |
68 | 68 | ],
|
69 | 69 | 'an object that implements `toJson`' => [
|
70 |
| - 'parameter' => new class () { |
| 70 | + new class () { |
71 | 71 | public function toJson()
|
72 | 72 | {
|
73 | 73 | return json_encode(['jsonKey' => 'jsonValue']);
|
74 | 74 | }
|
75 | 75 | },
|
76 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'0\'] = {"jsonKey":"jsonValue"};</script>', |
| 76 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'0\'] = {"jsonKey":"jsonValue"};</script>', |
77 | 77 | ],
|
78 | 78 | 'an object that implements `toString`' => [
|
79 |
| - 'parameter' => new class () { |
| 79 | + new class () { |
80 | 80 | public function __toString()
|
81 | 81 | {
|
82 | 82 | return 'string';
|
83 | 83 | }
|
84 | 84 | },
|
85 |
| - 'expected' => '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'0\'] = \'string\';</script>', |
| 85 | + '<script>window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'0\'] = \'string\';</script>', |
86 | 86 | ],
|
87 | 87 |
|
88 | 88 | ]);
|
89 | 89 |
|
90 |
| -it('can render data without a namespace') |
91 |
| - ->tap(fn () => config()->set('blade-javascript.namespace', '')) |
92 |
| - ->expect(fn () => renderView('keyValue')) |
93 |
| - ->toEqual('<script>window[\'key\'] = \'value\';</script>'); |
| 90 | +it('can render data without a namespace', function () { |
| 91 | + config()->set('blade-javascript.namespace', ''); |
| 92 | + expect(renderView('keyValue')) |
| 93 | + ->toEqual('<script>window[\'key\'] = \'value\';</script>'); |
| 94 | +}); |
94 | 95 |
|
95 | 96 | it('cannot translate resources to Javascript')
|
96 | 97 | ->tap(fn () => renderView('variable', ['parameter' => fopen(__FILE__, 'r')]))
|
97 | 98 | ->throws(ErrorException::class);
|
98 | 99 |
|
99 |
| -it('can render a customized view') |
100 |
| - ->tap(fn () => view()->replaceNamespace('bladeJavaScript', [__DIR__ . '/resources/views/override'])) |
101 |
| - ->expect(fn () => renderView('keyValue')) |
102 |
| - ->toEqual('<script type="application/javascript">window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'key\'] = \'value\';</script>'); |
| 100 | +it('can render a customized view', function () { |
| 101 | + view()->replaceNamespace('bladeJavaScript', [__DIR__ . '/resources/views/override']); |
| 102 | + expect(renderView('keyValue')) |
| 103 | + ->toEqual('<script type="application/javascript">window[\'js\'] = window[\'js\'] || {};window[\'js\'][\'key\'] = \'value\';</script>'); |
| 104 | +}); |
0 commit comments