|
| 1 | +import TransformTestCase from '../utils/transform-test-case'; |
| 2 | +import { moduleFor, RenderingTestCase } from 'internal-test-helpers'; |
| 3 | + |
| 4 | +moduleFor( |
| 5 | + 'ember-template-compiler: transforming attrs into @args', |
| 6 | + class extends TransformTestCase { |
| 7 | + ['@test it transforms attrs into @args']() { |
| 8 | + expectDeprecation(() => { |
| 9 | + this.assertTransformed(`{{attrs.foo}}`, `{{@foo}}`); |
| 10 | + }, /Using {{attrs}} to reference named arguments has been deprecated. {{attrs.foo}} should be updated to {{@foo}}./); |
| 11 | + |
| 12 | + expectDeprecation(() => { |
| 13 | + this.assertTransformed(`{{attrs.foo.bar}}`, `{{@foo.bar}}`); |
| 14 | + }, /Using {{attrs}} to reference named arguments has been deprecated. {{attrs.foo.bar}} should be updated to {{@foo.bar}}./); |
| 15 | + |
| 16 | + expectDeprecation(() => { |
| 17 | + this.assertTransformed(`{{if attrs.foo "foo"}}`, `{{if @foo "foo"}}`); |
| 18 | + }, /Using {{attrs}} to reference named arguments has been deprecated. {{attrs.foo}} should be updated to {{@foo}}./); |
| 19 | + |
| 20 | + expectDeprecation(() => { |
| 21 | + this.assertTransformed(`{{#if attrs.foo}}{{/if}}`, `{{#if @foo}}{{/if}}`); |
| 22 | + }, /Using {{attrs}} to reference named arguments has been deprecated. {{attrs.foo}} should be updated to {{@foo}}./); |
| 23 | + |
| 24 | + expectDeprecation(() => { |
| 25 | + this.assertTransformed(`{{deeply (nested attrs.foo.bar)}}`, `{{deeply (nested @foo.bar)}}`); |
| 26 | + }, /Using {{attrs}} to reference named arguments has been deprecated. {{attrs.foo.bar}} should be updated to {{@foo.bar}}./); |
| 27 | + |
| 28 | + expectDeprecation(() => { |
| 29 | + this.assertTransformed(`{{this.attrs.foo}}`, `{{@foo}}`); |
| 30 | + }, /Using {{attrs}} to reference named arguments has been deprecated. {{attrs.foo}} should be updated to {{@foo}}./); |
| 31 | + } |
| 32 | + } |
| 33 | +); |
| 34 | + |
| 35 | +moduleFor( |
| 36 | + 'ember-template-compiler: not transforming block params named "attrs" into @args', |
| 37 | + class extends RenderingTestCase { |
| 38 | + ["@test it doesn't transform block params"]() { |
| 39 | + this.registerComponent('foo', { |
| 40 | + template: '{{#let "foo" as |attrs|}}{{attrs}}{{/let}}', |
| 41 | + }); |
| 42 | + this.render('<Foo />'); |
| 43 | + this.assertComponentElement(this.firstChild, { content: 'foo' }); |
| 44 | + } |
| 45 | + |
| 46 | + ["@test it doesn't transform component block params"]() { |
| 47 | + this.registerComponent('foo', { |
| 48 | + template: '{{yield "foo"}}', |
| 49 | + }); |
| 50 | + this.render('<Foo as |attrs|>{{attrs}}</Foo>'); |
| 51 | + this.assertComponentElement(this.firstChild, { content: 'foo' }); |
| 52 | + } |
| 53 | + |
| 54 | + ["@test it doesn't transform block params with nested keys"]() { |
| 55 | + this.registerComponent('foo', { |
| 56 | + template: '{{yield (hash bar="baz")}}', |
| 57 | + }); |
| 58 | + this.render('<Foo as |attrs|>{{attrs.bar}}</Foo>'); |
| 59 | + this.assertComponentElement(this.firstChild, { content: 'baz' }); |
| 60 | + } |
| 61 | + } |
| 62 | +); |
0 commit comments