Re: [jasmine-js] Another Noobie: Examples , (Hidden) Docs for Node?

58 views
Skip to first unread message

Tim Wright

unread,
Nov 6, 2016, 1:40:24 AM11/6/16
to jasmi...@googlegroups.com

Hi Joe,

Both came to me - might have been a forum bug. Note I'm not a moderator/maintainer of Jasmine. But might be able to help with your questions :)

First, I'm not sure from your question, but it sounds like you're trying to write an end to end test - a test that simulates some browser action and then updates some backend state. From my experience, Jasmine is not the best tool for this type of test - you likely want Selenium (or even Concordion - disclaimer that I am a maintainer of Concordion :) 

Jasmine is really good for targeted unit tests - things like "when a button is clicked, a particular JS function is invoked" and "when that function is invoked, the system makes an AJAX REST call to the backend" and then so on testing each step in the chain independently. 

For some sample tests, I wrote a couple of blog posts recently. They're here: https://the-ambient-forest.blogspot.co.nz/

Hope that helps,

Tim



On 6 November 2016 at 19:22, Joe Chambley <jch...@gmail.com> wrote:
This is a duplicate of my earlier question - the forum didn't appear to take my earlier post.  Moderator ... help?


On Sat, Nov 5, 2016 at 7:19 PM, Joe Chambley <jch...@gmail.com> wrote:
I've looked at the suggested documentation at the Jasmine website, and at the corresponding examples, but I am wondering

1) Is there some documentation somewhere showing how to run a client browser test (using jasmine.ci, I'm guessing)?

2) Also, it'd be great to see a short example using node from the call to node.js to some server end javascript processing as well as client script proecessing.

I realize that jasmine is free, which is very cool, but at this point learning how to use it seems like learning how to use node before I discovered, The Node Beginner Book.  Wondering what I'm missing.

If anyone can point to some examples or other documentation, it'd be greatly appreciated.  Thank you for your time.

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

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

Joe Chambley

unread,
Nov 6, 2016, 1:50:01 AM11/6/16
to Jasmine
Thanks, I'll check your blog posts!


On Saturday, November 5, 2016 at 11:40:24 PM UTC-7, Tim Wright wrote:

Hi Joe,

Both came to me - might have been a forum bug. Note I'm not a moderator/maintainer of Jasmine. But might be able to help with your questions :)

First, I'm not sure from your question, but it sounds like you're trying to write an end to end test - a test that simulates some browser action and then updates some backend state. From my experience, Jasmine is not the best tool for this type of test - you likely want Selenium (or even Concordion - disclaimer that I am a maintainer of Concordion :) 

Jasmine is really good for targeted unit tests - things like "when a button is clicked, a particular JS function is invoked" and "when that function is invoked, the system makes an AJAX REST call to the backend" and then so on testing each step in the chain independently. 

For some sample tests, I wrote a couple of blog posts recently. They're here: https://the-ambient-forest.blogspot.co.nz/

Hope that helps,

Tim

On 6 November 2016 at 19:22, Joe Chambley <jch...@gmail.com> wrote:
This is a duplicate of my earlier question - the forum didn't appear to take my earlier post.  Moderator ... help?
On Sat, Nov 5, 2016 at 7:19 PM, Joe Chambley <jch...@gmail.com> wrote:
I've looked at the suggested documentation at the Jasmine website, and at the corresponding examples, but I am wondering

1) Is there some documentation somewhere showing how to run a client browser test (using jasmine.ci, I'm guessing)?

2) Also, it'd be great to see a short example using node from the call to node.js to some server end javascript processing as well as client script proecessing.

I realize that jasmine is free, which is very cool, but at this point learning how to use it seems like learning how to use node before I discovered, The Node Beginner Book.  Wondering what I'm missing.

If anyone can point to some examples or other documentation, it'd be greatly appreciated.  Thank you for your time.

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.

To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at https://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.

Tim Wright

unread,
Nov 6, 2016, 2:07:08 AM11/6/16
to jasmi...@googlegroups.com

No probs - the blog posts are quite basic, but might be a good start. 

TBH, I found this book excellent:


It doesn't cover unit testing Node, but is a great quickstart to getting Jasmine up and running!

Tim
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+unsubscribe@googlegroups.com.

Joe Chambley

unread,
Nov 7, 2016, 1:59:16 AM11/7/16
to Jasmine
Thank you, Tim, I will check the book out, too.

I looked at your blog, and I didn't find reference to html element tags that I was expecting. I searched for "form" on your blog, since the post that you directed me to involved testing a logon form.  I also searched for "html", and didn't find any tag reference.

So, I'm guessing that with Jasmine, perhaps, you don't actually call code with html elements, but indirectly access some functions which manage the DOM and return certain values that are in turn used for Jasmine "expect" comparisons.  Is that correct?

Tim Wright

unread,
Nov 7, 2016, 2:05:41 AM11/7/16
to jasmi...@googlegroups.com
That's a good point about the HTML Form. I'm testing a React component - so you won't see conventional HTML. And it looks like I don't actually have the code for the Login form anywhere in the blog - which is a "slight" oversight!

Tim
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+unsubscribe@googlegroups.com.

Joe Chambley

unread,
Nov 8, 2016, 5:49:06 PM11/8/16
to Jasmine
If I use SprecRunner.html, I can load jasmine now and the spec and my source.  What I need is the node environment because my source uses "require".  Maybe, I'll ask this as a separate question.
Joe

Tim Wright

unread,
Nov 8, 2016, 6:35:38 PM11/8/16
to jasmi...@googlegroups.com

Aaah, now I see what you're trying to do.

I split my browser and node tests entirely. To run the browser tests, I use karma (which is similar to the SpecRunner method). For node tests, I invoke Jasmine directly using:

node ./node_modules/jasmine/bin/jasmine.js

and then I have: /spec/support/jasmine.json containing this:

{
  "spec_dir": "functions",
  "spec_files": [
    "**/*[s|S]pec.js"
  ],
  "helpers": [
    "./node_modules/jasmine-es6/lib/install.js",
    "./spec/helpers/**/*.js"
  ],
  "stopSpecOnExpectationFailure": false,
  "random": false
}

Hope that helps a bit.

To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+unsubscribe@googlegroups.com.

Joe Chambley

unread,
Nov 10, 2016, 7:15:10 PM11/10/16
to Jasmine
Yes, that is, helpful, Tim.  I appreciate it.  Mind, if I contact you via google groups email or your blog, going forward?
Joe


On Saturday, November 5, 2016 at 11:40:24 PM UTC-7, Tim Wright wrote:

Hi Joe,

Both came to me - might have been a forum bug. Note I'm not a moderator/maintainer of Jasmine. But might be able to help with your questions :)

First, I'm not sure from your question, but it sounds like you're trying to write an end to end test - a test that simulates some browser action and then updates some backend state. From my experience, Jasmine is not the best tool for this type of test - you likely want Selenium (or even Concordion - disclaimer that I am a maintainer of Concordion :) 

Jasmine is really good for targeted unit tests - things like "when a button is clicked, a particular JS function is invoked" and "when that function is invoked, the system makes an AJAX REST call to the backend" and then so on testing each step in the chain independently. 

For some sample tests, I wrote a couple of blog posts recently. They're here: https://the-ambient-forest.blogspot.co.nz/

Hope that helps,

Tim

On 6 November 2016 at 19:22, Joe Chambley <jch...@gmail.com> wrote:
This is a duplicate of my earlier question - the forum didn't appear to take my earlier post.  Moderator ... help?
On Sat, Nov 5, 2016 at 7:19 PM, Joe Chambley <jch...@gmail.com> wrote:
I've looked at the suggested documentation at the Jasmine website, and at the corresponding examples, but I am wondering

1) Is there some documentation somewhere showing how to run a client browser test (using jasmine.ci, I'm guessing)?

2) Also, it'd be great to see a short example using node from the call to node.js to some server end javascript processing as well as client script proecessing.

I realize that jasmine is free, which is very cool, but at this point learning how to use it seems like learning how to use node before I discovered, The Node Beginner Book.  Wondering what I'm missing.

If anyone can point to some examples or other documentation, it'd be greatly appreciated.  Thank you for your time.

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.

To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at https://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.

Joe Chambley

unread,
Nov 14, 2016, 2:14:01 AM11/14/16
to Jasmine
In keeping things separate, I'm guessing that you start up a node server and eventually call a function that handles DOM interactions and then returns a relevant value to your node code?

Tim Wright

unread,
Nov 14, 2016, 2:35:08 AM11/14/16
to jasmi...@googlegroups.com

Hey Jo,

My architecture is quite different - which might make my strategy less useful But here goes. Basically I've got a single page web app. So I've got *heaps* of client side javascript that's making API calls to the backend and receiving JSON formatted data. Based on the data, the client side javascript rewrites the DOM to display what it wants (I'm using the React framework for the DOM construction on the client). To test that, I write small unit tests to check each piece of my code is working as expected. For example, I'd have at least these unit tests for a simple event:
* user event triggers the right bit of JS code
* JS code calls a method on my 'backendService' object
* JS code updates the model based on the result
* Error handling if call fails
* Loading overlays are shown (and hidden)

Then there's a set of separate tests for the backendService object. That way I've decoupled the backend from the front end. All those tests are run independently from the backend - and are run in a browser environment using jasmine and karma.

To test the backend, I take API events and usually have seperate unit tests (or multiple ones) for each of the following things:
* The incoming data is validated & cleansed properly
* The right DB calls have been made
* Errors are handled sensibly
* Etc.

For those, I spin up a node environment, start a local database server, and run the tests. Spinning up node turns out to be pretty easy for those tests - because when you run jasmine like this:

node ./node_modules/jasmine/bin/jasmine.js

you've actually started node!

Hope that helps.

Tim






To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages