Created
February 10, 2015 09:18
-
-
Save volkovasystems/a1cf3b3d440710516ffe to your computer and use it in GitHub Desktop.
Testing Dependency Injected Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Let's assume this is inside a qunit setup function. | |
//First we create our environment | |
var window = { | |
//Pass all global variables here. | |
//You can also attach mocks here. | |
"angular": { | |
"forEach": _.each | |
} | |
} | |
//The extracted function will be stored like this. | |
var sidebarController = "var sidebarController = function( $scope, $attrs ){.."; | |
//This will eval our function and attach it to window. | |
vm.runInNewContext( sidebarController, window ); | |
//This will be the scope inside the function the "this" | |
//This will let us inspect if it really attaches the functions needed. | |
var scope = { }; | |
//Extract out the function from the window but bind the scope first. | |
this.sidebarController = window.sidebarController.bind( scope ); | |
//Store the scope for later inspection in the test cases. | |
this.scope = scope; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment