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 1
1
import { moduleFor , test } from 'ember-qunit' ;
2
-
2
+
3
3
moduleFor ( 'service:foo-bar' , 'Unit | Service | FooBar' , {
4
4
} ) ;
5
5
6
6
test ( 'it exists' , function ( assert ) {
7
7
this . inject . service ( 'foo' ) ;
8
8
this . inject . service ( 'foo' , { as : 'bar' } ) ;
9
- } ) ;
9
+ } ) ;
10
10
11
11
test ( 'it works for controllers' , function ( assert ) {
12
12
this . inject . controller ( 'foo' ) ;
@@ -16,3 +16,19 @@ test('it works for controllers', function(assert) {
16
16
test ( 'handles dasherized names' , function ( assert ) {
17
17
this . inject . service ( 'foo-bar' ) ;
18
18
} ) ;
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) {
17
17
test ( 'handles dasherized names' , function ( assert ) {
18
18
this [ 'foo-bar' ] = this . owner . lookup ( 'service:foo-bar' ) ;
19
19
} ) ;
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
+ } ) ;
20
30
} ) ;
Original file line number Diff line number Diff line change @@ -861,6 +861,12 @@ module.exports = function(file, api) {
861
861
}
862
862
}
863
863
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
+
864
870
function updateInjectCalls ( ctx ) {
865
871
ctx
866
872
. find ( j . CallExpression , {
@@ -878,13 +884,16 @@ module.exports = function(file, api) {
878
884
} )
879
885
. forEach ( p => {
880
886
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 ( '' ) ;
882
890
let localName = injectedName ;
883
891
if ( p . node . arguments [ 1 ] ) {
884
892
let options = p . node . arguments [ 1 ] ;
885
893
let as = options . properties . find ( property => property . key . name === 'as' ) ;
886
894
if ( as ) {
887
- localName = as . value . value ;
895
+ let flattenValue = flatten ( as . value ) ;
896
+ localName = flattenValue . map ( node => node . value ) . join ( '' ) ;
888
897
}
889
898
}
890
899
let property = j . identifier ( localName ) ;
You can’t perform that action at this time.
0 commit comments