Mocha and ZombieJS

前端 未结 4 1246
Happy的楠姐
Happy的楠姐 2020-12-08 01:48

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

4条回答
  •  广开言路
    2020-12-08 02:04

    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.

提交回复
热议问题