Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="mocha"></div>

              
            
!

CSS

              
                
              
            
!

JS

              
                // MOCHA - test

// UI
mocha.setup('bdd')

// CHAI
var assert = chai.assert;
var expect = chai.expect;
var should = chai.should();

// TESTS
// Assertions
describe("Assertions", function(){
	var a = 1;
    it("should", function(){
      a.should.equal(1)
  	})    
  	it("expect", function(){
      expect(a).to.equal(1);
  	})
  	it("assert", function(){
      assert.equal(a, 1);
  	})  
})

// Multiple specs
describe("Multiple specs", function() {
    it("should be true", function() {
        expect(true).to.be.true;
    });
    it("should be able to add 1 to 1", function() {
        expect(1+1).to.equal(2);
    });
});

// Synchronous code
describe('Synchronous code', function(){
  describe('#indexOf()', function(){
    it('should return -1 when the value is not present', function(){
      expect([1,2,3].indexOf(5)).to.equal(-1);
      expect([1,2,3].indexOf(0)).to.equal(-1);
    })
  })
})

// Asynchronous code
describe("Asynchronous code", function() {
	it("should be true - async", function(done) {
		setTimeout(function() {
			expect(true).to.be.true;
			done();
		}, 1000);
	})
})

describe('Asynchronous code', function(){
	describe('myNumber()', function(){
		it('should equal 3 - async', function(done){
			var testPerson = new Person();
			expect(testPerson.myNumber()).to.equal(3);
			done();
		})
	})
})

// Throw an error
describe("Throw an error", function() {
	it("should throw a custom error - async", function(done) {
		var testPerson = new Person();
		testPerson.showAnError(function(err){
       		if (err) throw err;
        	done();
      	});
	})
})

// Hooks
describe('hooks', function() {
	var example1 = 0;

	beforeEach('adds 2', function(){
		// runs before each test in this block
		example1 += 1;
	})

	afterEach('sets example1 to 0', function(){
		// runs after each test in this block
		example1 = 0;
	})

	// test cases
	it("beforeEach() and afterEach()", function() {
		expect(example1).to.equal(1);
		example1 += 1;
	});	

	it("resets variable between specs", function() {
		expect(example1).to.equal(1);
	});


	var example2;


	before('sets variables to 0', function() {
	// runs before all tests in this block
		example2 = 1;

	})

	after('sets variables to their initial values', function(){
		// runs after all tests in this block
		example2 = 0;
	})

	// test cases
	it("before() and after()", function() {
		expect(example1).to.equal(1);
		example2 += 1;
	})

	it("does not reset variable between specs", function() {
		expect(example2).to.equal(2);
	})
})


// Pending tests
describe('Pending tests', function(){
    it('true is true'
    	// , function(){
    	// expect(true).to.equal(true);
    	// }
    )
})


// Exclusive tests
describe("Exclusive tests", function(){
	var example1 = 1;
	var example2 = 2;

	it("should equal 1", function(){
		expect(example1).to.equal(1);
	})
	// // run only the specified suite or test by appending .only() to the call
	// it.only("should equal 2", function(){
	// 	expect(example2).to.equal(2);
	// })
})


// Inclusive tests
describe("Exclusive tests", function(){
	var example1 = 1;
	var example2 = 2;

	it("should equal 1", function(){
		expect(example1).to.equal(1);
	})
	// by appending .skip() you may tell Mocha to simply ignore these suite(s) and test-case(s)
	it.skip("should equal 2", function(){
		expect(example2).to.equal(2);
	})
})

// RUN MOCHA
mocha.run()
              
            
!
999px

Console