@@ -22,15 +22,37 @@ describe('plugin api', function () {
22
22
router . stateRegistry . stateQueue . autoFlush ( $state ) ;
23
23
} ) ;
24
24
25
- class FancyPlugin implements UIRouterPlugin {
25
+ class FancyPluginClass implements UIRouterPlugin {
26
26
constructor ( public router : UIRouter ) { }
27
27
name = "fancyplugin"
28
28
}
29
29
30
+ function FancyPluginConstructor ( router : UIRouter , options : any ) {
31
+ this . name = "fancyplugin" ;
32
+ }
33
+
30
34
describe ( 'initialization' , ( ) => {
35
+ it ( 'should accept a plugin class' , ( ) => {
36
+ let plugin = router . plugin ( FancyPluginClass ) ;
37
+ expect ( plugin instanceof FancyPluginClass ) . toBeTruthy ( ) ;
38
+ } ) ;
39
+
40
+ it ( 'should accept a constructor function' , ( ) => {
41
+ let plugin = router . plugin ( FancyPluginConstructor ) ;
42
+ expect ( plugin instanceof FancyPluginConstructor ) . toBeTruthy ( ) ;
43
+ } ) ;
44
+
45
+ it ( 'should accept a factory function' , ( ) => {
46
+ function factoryFn ( router : UIRouter , options : any ) {
47
+ return new FancyPluginClass ( router ) ;
48
+ }
49
+ let plugin = router . plugin ( factoryFn ) ;
50
+ expect ( plugin instanceof FancyPluginClass ) . toBeTruthy ( ) ;
51
+ } ) ;
52
+
31
53
it ( 'should return an instance of the plugin' , ( ) => {
32
- let plugin = router . plugin ( ( ) => new FancyPlugin ( router ) ) ;
33
- expect ( plugin instanceof FancyPlugin ) . toBeTruthy ( ) ;
54
+ let plugin = router . plugin ( ( ) => new FancyPluginClass ( router ) ) ;
55
+ expect ( plugin instanceof FancyPluginClass ) . toBeTruthy ( ) ;
34
56
} ) ;
35
57
36
58
it ( 'should pass the router instance to the plugin constructor' , ( ) => {
@@ -55,9 +77,9 @@ describe('plugin api', function () {
55
77
56
78
describe ( 'getPlugin' , ( ) => {
57
79
it ( 'should return the plugin instance' , ( ) => {
58
- router . plugin ( ( ) => new FancyPlugin ( router ) ) ;
80
+ router . plugin ( ( ) => new FancyPluginClass ( router ) ) ;
59
81
let plugin = router . getPlugin ( 'fancyplugin' ) ;
60
- expect ( plugin instanceof FancyPlugin ) . toBeTruthy ( ) ;
82
+ expect ( plugin instanceof FancyPluginClass ) . toBeTruthy ( ) ;
61
83
} ) ;
62
84
} )
63
85
} ) ;
0 commit comments