Closed carson-song-lsq closed 9 years ago
To make it work, I did a quick fix as below. This might not be a good solution for the root cause, can you take a look at it?
function bardInject() {
//line 301 var names = []; angular.forEach(args, function (name, ix) {
//myFix Start
if (!angular.isString(name)) { return; }
//End of Fix
var value = $injector.get(name);
if (value == null) { return; }
Hello Carson Song.
Thanks for your report and your interest in bard.js.
You have identified two problems in the current version (v.0.1.2).
bardInject
when its first arg is this
I should mention it in the README ... and I will. I'll also tell people to include it among the scripts loaded for their tests.
FWIW, the bower.json and package.json clearly announce the dependence on sinon. Did you use bower or npm to install bard. Those are the instructions. If not how did you get it?
I imagine you simply grabbed the library from the repo ... perhaps because you wanted to use Jasmine instead of Mocha.
bardInject
would have stripped the this
from the front of your argument list ... if you were using mocha. That's what getCtxFromArgs
does ... or tries to do. getCtxFromArgs
doesn't really know what the first arg is so it looks for a clue ... and the clue it is looking for is a mocha method called test
. If it doesn't see that member, it doesn't remove the first arg (the this
in your case) from the args list.
But you're using jasmine not mocha. You really shouldn't be passing this
to bardInject
. Of course it is easy to see why you did ... because I told you to do so.
That's something to clarify too.
I just made a bunch of documentation changes and some code changes so that you won't be hurt running Jasmine even if you DO put this
in your arg list.
I still recommend that you remove it.
I've pushed these changes as v.0.1.3.
Please try them. I haven't run Jasmine with bard in a long time ... and I don't have an easy way to do so right now.
Appreciate the help!
Hi Ward Bell,
I like your effort on this, i'm trying to use bardJS to optimize our unit test(Jasmine+RequireJS+Angular), but get stuck by some issues.
When i try to use bard.inject(this, '$q') in beforeEach-block, it throw errors.
By debugging, i found the error happened in bard.js, is from here: angular.forEach(args, function(name, ix) { var value = $injector.get(name); //args=[this,'$q'] in my case. So, the args is supposed to remove the first argument this, right? Why it's not?
Do you have any insight about this?
Thanks, Carson Song