Live data from Hacker News

Unit Testing Best Practices in AngularJS

andyshora.com

11–17 of 17 posts

Re: Unit Testing Best Practices in AngularJS

#12
post #3

Client side testable code is one of the pinnacle of AngularJS. Reuseable declarative UI's through Directives, reuseable business logic throug Services and view models (controllers) having only knowledge of views is a really good for maintainablity of a complex javascript app. AngualrJS can beat any framework out there (Backbone, Ember, etc.) when it comes to having testable & manageable code. If your product is going…

Would you mind clarifying on how AngularJS is better than BackboneJS when it comes to having testable & manageable code? I am currently working setting up a unit testing environment with BackboneJS, it seems to be working well. What major differences exist when you test the two?

Re: Unit Testing Best Practices in AngularJS

#13
Great article. One thing I wish got more coverage is testing directives: it's already much easier than most DOM-testing methods (though it can't replace selenium etc.), but doing it well and consistently has proven difficult and I don't test most of my directives. For example, I had to modify the triggerHandler function in Angular to allow sending fake key presses since it didn't have a built in way (at least a few months ago) to specify the "which" property on the event.

Also, If you're in Chicago, the Angular meetup group will be talking about testing on November 20th: http://www.meetup.com/AngularJS-Chicago/

Re: Unit Testing Best Practices in AngularJS

#14
post #12
post #3

Client side testable code is one of the pinnacle of AngularJS. Reuseable declarative UI's through Directives, reuseable business logic throug Services and view models (controllers) having only knowledge of views is a really good for maintainablity of a complex javascript app. AngualrJS can beat any framework out there (Backbone, Ember, etc.) when it comes to having testable & manageable code. If your product is going…

Would you mind clarifying on how AngularJS is better than BackboneJS when it comes to having testable & manageable code? I am currently working setting up a unit testing environment with BackboneJS, it seems to be working well. What major differences exist when you test the two?

  1. DI.
  2. Clear separation of concerns.
I believe that writing testable Javascript has been possible since the name Javascript was invented. Angular.js has made it easier by doing its best to force you to write testable code.

Re: Unit Testing Best Practices in AngularJS

#15
post #13

Great article. One thing I wish got more coverage is testing directives: it's already much easier than most DOM-testing methods (though it can't replace selenium etc.), but doing it well and consistently has proven difficult and I don't test most of my directives. For example, I had to modify the triggerHandler function in Angular to allow sending fake key presses since it didn't have a built in way (at least a few m…

This. I've come to the conclusion that directive testing falls under two headers.

1, measuring the effects of the directive on the dom, e.g. rendering a list of orders. This reflects the state of the application and

2, e2e testing of directives with a real browser.

However, I'm not sure this is correct! I'd like to see some best practices listed by the Angular authors.

Re: Unit Testing Best Practices in AngularJS

#16
post #12

Earlier quoted context omitted.

Would you mind clarifying on how AngularJS is better than BackboneJS when it comes to having testable & manageable code? I am currently working setting up a unit testing environment with BackboneJS, it seems to be working well. What major differences exist when you test the two?

1. DI. 2. Clear separation of concerns. I believe that writing testable Javascript has been possible since the name Javascript was invented. Angular.js has made it easier by doing its best to force you to write testable code.

you can use DI in backbone and clearly seperate your concerns as well. It is just not as much enforced in the framework (not opinionated)

Re: Unit Testing Best Practices in AngularJS

#17

Earlier quoted context omitted.

1. DI. 2. Clear separation of concerns. I believe that writing testable Javascript has been possible since the name Javascript was invented. Angular.js has made it easier by doing its best to force you to write testable code.

you can use DI in backbone and clearly seperate your concerns as well. It is just not as much enforced in the framework (not opinionated)

So you agree with me.
Post reply on HN