Last active
June 18, 2016 11:20
-
-
Save DaveMBush/86f271faa70152675f0719d87a0268c4 to your computer and use it in GitHub Desktop.
Accessing ‘private’ JavaScript variables from Unit Tests
This file contains 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
function MyClass(){ | |
function privateMember(){ | |
} | |
function publicMember(){ | |
privateMember.apply(this); | |
} | |
this.publicMember = publicMember; | |
} |
This file contains 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
function MyClass(){ | |
function privateMember(){ | |
} | |
function publicMember(){ | |
privateMember.apply(this); | |
} | |
this.publicMember = publicMember; | |
if(jasmine){ | |
this.privateMember = privateMember; | |
} | |
} |
This file contains 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
function MyClass(){ | |
function privateMember(){ | |
} | |
function publicMember(){ | |
privateMember.apply(this); | |
} | |
var oldPrivateMember; | |
this.publicMember = publicMember; | |
if(jasmine){ | |
if(oldPrivateMember){ | |
privateMember = oldPrivateMember; | |
} else { | |
oldPrivateMember = privateMember; | |
} | |
this.privateMember = privateMember; | |
privateMember = (function(){ | |
this.privateMember(); | |
}).bind(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment