File tree Expand file tree Collapse file tree 3 files changed +39
-4
lines changed
transforms/convert-module-for-to-setup-test Expand file tree Collapse file tree 3 files changed +39
-4
lines changed Original file line number Diff line number Diff line change 11import { moduleFor , test } from 'ember-qunit' ;
2-
2+
33moduleFor ( 'service:foo-bar' , 'Unit | Service | FooBar' , {
44} ) ;
55
66test ( 'it exists' , function ( assert ) {
77 this . inject . service ( 'foo' ) ;
88 this . inject . service ( 'foo' , { as : 'bar' } ) ;
9- } ) ;
9+ } ) ;
1010
1111test ( 'it works for controllers' , function ( assert ) {
1212 this . inject . controller ( 'foo' ) ;
@@ -16,3 +16,19 @@ test('it works for controllers', function(assert) {
1616test ( 'handles dasherized names' , function ( assert ) {
1717 this . inject . service ( 'foo-bar' ) ;
1818} ) ;
19+
20+ test ( 'handle cuted (long) services names' , function ( assert ) {
21+ this . inject . service ( 'foo-bar-with-a' +
22+ '-very-long-name' ) ;
23+ this . inject . service ( 'foo-bar-with-a' +
24+ '-very-long-name' , { as : 'foo-bar-with-a' +
25+ '-very-long-name' } ) ;
26+ } ) ;
27+
28+ test ( 'handle cuted (long) controllers names' , function ( assert ) {
29+ this . inject . controller ( 'foo-bar-with-a' +
30+ '-very-long-name' ) ;
31+ this . inject . controller ( 'foo-bar-with-a' +
32+ '-very-long-name' , { as : 'foo-bar-with-a' +
33+ '-very-long-name' } ) ;
34+ } ) ;
Original file line number Diff line number Diff line change @@ -17,4 +17,14 @@ module('Unit | Service | FooBar', function(hooks) {
1717 test ( 'handles dasherized names' , function ( assert ) {
1818 this [ 'foo-bar' ] = this . owner . lookup ( 'service:foo-bar' ) ;
1919 } ) ;
20+
21+ test ( 'handle cuted (long) services names' , function ( assert ) {
22+ this [ 'foo-bar-with-a-very-long-name' ] = this . owner . lookup ( 'service:foo-bar-with-a-very-long-name' ) ;
23+ this [ 'foo-bar-with-a-very-long-name' ] = this . owner . lookup ( 'service:foo-bar-with-a-very-long-name' ) ;
24+ } ) ;
25+
26+ test ( 'handle cuted (long) controllers names' , function ( assert ) {
27+ this [ 'foo-bar-with-a-very-long-name' ] = this . owner . lookup ( 'controller:foo-bar-with-a-very-long-name' ) ;
28+ this [ 'foo-bar-with-a-very-long-name' ] = this . owner . lookup ( 'controller:foo-bar-with-a-very-long-name' ) ;
29+ } ) ;
2030} ) ;
Original file line number Diff line number Diff line change @@ -861,6 +861,12 @@ module.exports = function(file, api) {
861861 }
862862 }
863863
864+ function flatten ( node ) {
865+ const isBE = node . type === 'BinaryExpression' ;
866+ const isPLUS = node . operator === '+' ;
867+ return isBE && isPLUS ? [ ...flatten ( node . left ) , ...flatten ( node . right ) ] : [ node ] ;
868+ }
869+
864870 function updateInjectCalls ( ctx ) {
865871 ctx
866872 . find ( j . CallExpression , {
@@ -878,13 +884,16 @@ module.exports = function(file, api) {
878884 } )
879885 . forEach ( p => {
880886 let injectType = p . node . callee . property . name ;
881- let injectedName = p . node . arguments [ 0 ] . value ;
887+ let injectedName = flatten ( p . node . arguments [ 0 ] )
888+ . map ( node => node . value )
889+ . join ( '' ) ;
882890 let localName = injectedName ;
883891 if ( p . node . arguments [ 1 ] ) {
884892 let options = p . node . arguments [ 1 ] ;
885893 let as = options . properties . find ( property => property . key . name === 'as' ) ;
886894 if ( as ) {
887- localName = as . value . value ;
895+ let flattenValue = flatten ( as . value ) ;
896+ localName = flattenValue . map ( node => node . value ) . join ( '' ) ;
888897 }
889898 }
890899 let property = j . identifier ( localName ) ;
You can’t perform that action at this time.
0 commit comments