Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
318 views
in Technique[技术] by (71.8m points)

node.js - Mocha and ZombieJS

I'm starting a nodejs project and would like to do BDD with Mocha and Zombiejs. Unfortunately I'm new to just about every buzzword in that sentence. I can get Mocha and Zombiejs running tests fine, but I can't seem to integrate the two - is it possible to use Mocha to run Zombiejs tests, and if so, how would that look?

Just looking for "hello world" to get me started, but a tutorial/example would be even better.

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Assuming you already have installed mocha, zombie and expect.js according to instructions, this should work for you:

// Put below in a file in your *test* folder, ie: test/sampletest.js:

var expect = require('expect.js'),
Browser = require('zombie'),
browser = new Browser();

describe('Loads pages', function(){

    it('Google.com', function(done){

        browser.visit("http://www.google.com", function () {
            expect(browser.text("title")).to.equal('Google');
            done();
        });
    });

});

Then you should be able to run the mocha command from your root application folder:

# mocha -R spec

  Loads pages
    ? Google.com (873ms)


  ? 1 tests complete (876ms)

Note: If your tests keep failing due to timeouts, it helps to increase mocha's timeout setting a bit by using the -t argument. Check out mocha's documentation for complete details.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...