How to setUp and tearDown Test Data Files Using MOCHA?

415 views
Skip to first unread message

JPJen

unread,
Jun 10, 2014, 11:44:35 AM6/10/14
to moc...@googlegroups.com
Hi, I have written mocha unit tests, which run well and as expected.  Thanks to lots help that I had received on the Forum.
 
Before I run those mocha unit tests, I had loaded test data "files" manually into the MongoDB (My NodeJS project can post data files and I have the URL that establishes the connection to the MongoDB database on the server.)  And I use a tool: Advanced REST Client.  By the way, I had three different data files and I must load each of those files many times.

I wish that I could load data files programmatically like using the setup and teardown methods in JUnit instead of doing it manually.  Can anybody tell me how to do it ( I have been searching on the internet for an example)?  Thank you very much. 


vision media [ Tj Holowaychuk ]

unread,
Jun 10, 2014, 12:02:20 PM6/10/14
to moc...@googlegroups.com
you can have file-level before()/after() functions, ex:

before(function(done){
  loadFixturesIntoMongo(done);
});

that sort of idea


--
You received this message because you are subscribed to the Google Groups "Mocha" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mochajs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vision media [ Tj Holowaychuk ]

unread,
Jun 10, 2014, 12:02:38 PM6/10/14
to moc...@googlegroups.com
or to be more terse: before(loadFixturesIntoMongo) in that case

JPJen

unread,
Jun 10, 2014, 1:47:38 PM6/10/14
to moc...@googlegroups.com, t...@vision-media.ca
How do I tear it down after I run all the unit tests?

vision media [ Tj Holowaychuk ]

unread,
Jun 10, 2014, 1:48:00 PM6/10/14
to moc...@googlegroups.com
after(someTearDownFunction)
Reply all
Reply to author
Forward
0 new messages