Basic Angular Testing with Injection

209 views
Skip to first unread message

Andy Joslin

unread,
May 26, 2012, 8:52:49 PM5/26/12
to ang...@googlegroups.com
Hey guys,

So I'm new to the whole testing thing (I've been one of those people who has said 'I should write unit tests...' but never ended up ever doing it :-p).
I'm now writing unit tests for this project.  I'm using testacular + Jasmine, with browserify to compile things.  I was having no problems until I started trying to do a lot angular-injection-stuff.

Right now I'm simply trying to do a test of ng-model to get my head around all of it.

I have a testacular.conf file which includes everything necessary: http://d.pr/n/VocZ
I have my controller defined: http://d.pr/n/nNaU (MainCtrl.coffee)
And I have my test itself: http://d.pr/n/5ucl (_MainCtrlTest.coffee, in same directory as MainCtrl.coffee)

The test fails immediately, with the input's elm.val() returning blank, and scope.hello returning the intended value ('initial', set in MainCtrl.coffee)

What am I doing wrong here?

Renan T. Fernandes

unread,
May 26, 2012, 10:03:48 PM5/26/12
to ang...@googlegroups.com
If I'm not wrong you should put a 'beforeEach module("MainCtrlTest")' before the 'beforeEach inject'.

Before each test your module need to be 'loaded' on the 'testing context'(don't know exactly how to call it).

2012/5/26 Andy Joslin <andyt...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/7uU7UwAIZhUJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.



--
Renan Fernandes(aka "ShadowBelmolve")

Vojta Jína

unread,
Jun 10, 2012, 2:10:10 AM6/10/12
to ang...@googlegroups.com
Yes, you need to do

beforeEach module 'MainCtrlTest'


V.
Reply all
Reply to author
Forward
0 new messages