Over a million developers have joined DZone.

Fast Site Testing with ExpectThat using CoffeeScript, Zombie, Mocha, and Node

· Web Dev Zone

Make the transition to Node.js if you are a Java, PHP, Rails or .NET developer with these resources to help jumpstart your Node.js knowledge plus pick up some development tips.  Brought to you in partnership with IBM.

A few posts ago, I showed how to use ExpectThat with Mocha and Node.js. Today, I'll show a simple example of using ExpectThat with Zombie.js--a full-stack testing framework.

Zombie.js

Zombie.js is a fast, headless testing framework that provides various functionality to write tests that hit your full technology stack. While I generally prefer to write more fine-grained, isolated tests, it's important to also have a few smoke tests and/or integration tests to verify end-to-end functionality. Zombie makes these kinds of tests easy, while allowing me to still use ExpectThat and Mocha.

The Example

Here's a simple example that populates two input elements and then verifies that the values of those input fields contain the expected text.

zombie = require("zombie")
require("expectThat.mocha")

browser = new zombie.Browser()

describe "When populating two text boxes", ->
  expectThat "they should have values of foo and bar", (done) ->
    browser.visit "http://127.0.0.1/~dmohl/mocha-zombie/specs.html", ->
      browser
        .fill(".search", "foo")
        .fill("#test", "bar")
      input1 = browser.querySelector ".search"
      input2 = browser.querySelector "#test"
      input1.value.should equal "foo"
      input2.value.should equal "bar"
      done()

You can find the full example here.

After a few commands such as " coffee --output lib/ specs/ " and " mocha 'lib/example.spec.js' --reporter spec ", you should see an output that looks something like this:


To learn more about ExpectThat, visit https://github.com/dmohl/expectThat.

 

Source: http://bloggemdano.blogspot.com/2012/02/expectthat-with-coffeescript-zombie.html

Learn why developers are gravitating towards Node and its ability to retain and leverage the skills of JavaScript developers and the ability to deliver projects faster than other languages can.  Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}