Mocha and ZombieJS

前端 未结 4 1241
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 01:53

    if you want to use cucumber-js for your acceptance tests and mocha for your "unit" tests for a page, you can use cuked-zombie (sorry for the advertising).

    Install it like described in the readme on github, but place your world config in a file called world-config.js

    `/* globals __dirname */
    var os = require('os');
    var path = require('path');
    
    module.exports = {
      cli: null,
      domain: 'addorange-macbook': 'my-testing-domain.com',
      debug: false
    };
    

    Then use mocha with zombie in your unit tests like this:

    var chai = require('chai'), expect = chai.expect;
    var cukedZombie = require('cuked-zombie');
    
    describe('Apopintments', function() {
    
      describe('ArrangeFormModel', function() {
        before(function(done) { // execute once
          var that = this;
    
          cukedZombie.infectWorld(this, require('../world-config'));
    
          this.world = new this.World(done);
    
          // this inherits the whole world api to your test
          _.merge(this, this.world);
        });
    
        describe("display", function() {
    
          before(function(done) { // executed once before all tests are run in the discribe display block
            var test = this;
            this.browser.authenticate().basic('maxmustermann', 'Ux394Ki');
    
            this.visitPage('/someurl', function() {
              test.helper = function() {
    
              };
    
              done();
            });
          });
    
          it("something on the /someurl page is returned", function() {
            expect(this.browser.html()).not.to.be.empty;
          });
    

提交回复
热议问题