Refreshing document on each spec execution

901 views
Skip to first unread message

Taner Diler

unread,
Mar 14, 2012, 4:14:14 AM3/14/12
to Jasmine
Hi all,

Jasmine is a good tool to test javascripts. Thanks.

I want to learn that there is a way to refresh document on each spec
execution. When I add a definition to document head on previous spec
execution, the definition is still there on next spec execution.

Aaron McLeod

unread,
Mar 14, 2012, 3:54:31 PM3/14/12
to jasmi...@googlegroups.com
If this definition is being done in a beforeEach(), then you can simply use an afterEach() to clean it up. What kind of definition are you adding exactly?

-- 
Aaron McLeod
http://agmprojects.com

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To post to this group, send email to jasmi...@googlegroups.com.
To unsubscribe from this group, send email to jasmine-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.

Rajan Agaskar

unread,
Mar 14, 2012, 3:55:39 PM3/14/12
to jasmi...@googlegroups.com
Right, we don't have a simple way for you to sandbox your global environment in between specs. For many people this tends not to be a problem. It *can* be achieved through iframes and some complicated script loading/scope juggling, but IME it hasn't been worth it. I don't know that this is going to be something you'll see soon in Jasmine. 

This can cause a problem if you're attaching events to document, etc. You can either unbind your events in an afterEach in your spec helper (essentially a global after each), or you can write your Javascript such that you never explicitly bind to a document element (instead, for example, binding to a passed in element). 

Aaron McLeod

unread,
Mar 14, 2012, 3:57:31 PM3/14/12
to jasmi...@googlegroups.com
While we're on the topic of manipulating the DOM, I know jasmine is largely about javascript unit testing, as supposed to integration. Wouldn't a different tool be more preferable if you are checking interaction? I could be wrong her about what the OP is doing, just a thought.

-- 
Aaron McLeod
http://agmprojects.com

Rajan Agaskar

unread,
Mar 16, 2012, 10:36:07 AM3/16/12
to jasmi...@googlegroups.com
I like to recommend some kind of selenium (cucumber/capybara provides a simple interface for selenium tests) for people who want full stack integration, but there is some convenience in being able to test DOM integration with Jasmine, since manipulation of the DOM is often the primary reason people are writing Javascript. Additionally, selenium/cucumber is surely the wrong level of testing when dealing with edge case behaviors of DOM manipulation (admittedly, the less coupled you are to the DOM, the nicer your Jasmine tests become). 

I'm not aware of any pure-Javascript solutions that are tailor-made for DOM-integration tests (but I'm sure they're out there, so if people know of them, speak up!); usually you can do a fair job of this in Jasmine, although it tends to involve *a lot* of setup (to be fair, this seems to be characteristic of most integration tests). My personal approach is to have a generic fixture which shares many of the qualities of the actual DOM I will be applying my Javascript to (to ensure my Javascript behavior is 'glued', I will use a cucumber happy path test -- I know some people prefer jasmine-fixtures that generate from actual views to deal with this problem). 

Thanks!

Rajan

Ken Chien

unread,
Mar 16, 2012, 10:40:37 AM3/16/12
to jasmi...@googlegroups.com


On Fri, Mar 16, 2012 at 10:36 AM, Rajan Agaskar <ra...@pivotallabs.com> wrote:

I'm not aware of any pure-Javascript solutions that are tailor-made for DOM-integration tests (but I'm sure they're out there, so if people know of them, speak up!); [snip]
 
I like Justin Searls' jasmine-fixture: https://github.com/searls/jasmine-fixture
It's easy to understand and it cleans up after itself after every spec.

Ken

Taner Diler

unread,
Mar 21, 2012, 5:01:51 AM3/21/12
to Jasmine
In beforeEach() method, I'm adding content to body element. I'm
executing my javascript codes - it holds some states. On next
execution, same content and same javascript states still there. When I
introduced with Jasmine, I taught that the jasmine template (js
libraries ext.) is reloaded on every spec execution.

If jasmine doesn't support this, as you said I need to write method to
reset current state.

thanks

On Mar 14, 9:54 pm, Aaron McLeod <sircoolgu...@gmail.com> wrote:
> If this definition is being done in a beforeEach(), then you can simply use an afterEach() to clean it up. What kind of definition are you adding exactly?
>
> --
> Aaron McLeodhttp://agmprojects.com
>
>
>
>
>
>
>
> On Wednesday, 14 March, 2012 at 4:14 AM, Taner Diler wrote:
> > Hi all,
>
> > Jasmine is a good tool to test javascripts. Thanks.
>
> > I want to learn that there is a way to refresh document on each spec
> > execution. When I add a definition to document head on previous spec
> > execution, the definition is still there on next spec execution.
>
> > --
> > You received this message because you are subscribed to the Google Groups "Jasmine" group.
> > To post to this group, send email to jasmi...@googlegroups.com (mailto:jasmi...@googlegroups.com).
> > To unsubscribe from this group, send email to jasmine-js+...@googlegroups.com (mailto:jasmine-js+...@googlegroups.com).
Reply all
Reply to author
Forward
0 new messages