当前位置: 动力学知识库 > 问答 > 编程问答 >

angularjs - Can I pass httpBackend mock to function in unit test

问题描述:

The following general stub works:

https://gist.github.com/anonymous/154172bd7e034f3608e9

My question is whether or not this will create unintended results. Does anyone disagree with the way I'm doing this?

My goal is to list the tests above the implementations so that its easy to read the specs for a given piece of functionality:

it('should ...', func);

it('should ...', func);

it('should ...', func);

function func() {...};

function func() {...};

function func() {...};

Thank you.

网友答案:

I think it is a good pattern to follow and I personally follow this pattern in my projects. I try to always place function declarations at the bottom. As you probably already know, this only works if you declare them the way you are doing and note assigning a function to a variable.

// Good
doSomething();
function doSomething() {}

// Error
doSomething();
var doSomething = function() {}

John Papa agrees- https://github.com/johnpapa/angular-styleguide#style-y034

网友答案:

Not For tests

Jasmine define clear verbose DSL, you should see the actuel test just inside the it(), people will look to tests (implementation) first to understand your project (because your tests are the actuel specs, what is your code doing ?).

True for APIs

In APIs, you want to see the public members first just by looking in the top like in the John Papa's style guide (I guess you are referring to it), this, make it clear, and easy to go from top to down.

网友答案:

It will not create unintended results, this is a fine style choice.

分享给朋友:
您可能感兴趣的文章:
随机阅读: