Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Mocha Tests</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
  </head>
  <body>
    <div id="info"></div>
    <div id="mocha"></div>

    <script src="https://unpkg.com/chai/chai.js"></script>
    <script src="https://unpkg.com/mocha/mocha.js"></script>
    
    <script>
      function add (a, b) {
        return a + b;
      }
    </script>

    <script class="mocha-init">
      // Mocha's "interface" system allows developers to choose their style of DSL. Mocha has BDD, TDD, Exports, QUnit and Require-style interfaces.
      mocha.setup('bdd');

      // What is bdd interfaces

      // The BDD interface provides describe(), context(), it(), specify(), before(), after(), beforeEach(), and afterEach().
      // context() is just an alias for describe(), and behaves the same way; it just provides a way to keep tests easier to read and organized. Similarly, specify() is an alias for it().
      
      // Use this option to have Mocha check for global variables that are leaked while running tests. Specify globals that are acceptable via the --global option (for example: --check-leaks --global jQuery --global MyLib).
      mocha.checkLeaks();

    </script>
    <script>
      const assert = chai.assert

      describe('Async demo', function () {
        let testData

        before(async function() {
          info.textContent += 'runs before all | '

          await fetch("https://codepen.io/jobs.json")
            .then(response => response.json())
            .then(data => {
              testData = data;
            }); 
        })

        it('jobs length should be 26', function () {
          assert.equal(testData.jobs.length, 27)
        })

        it('succeed when random > 0.1', function (done) {
          setTimeout(function () {
            if (Math.random() > 0.1) {
              done()
            } else {
              done('random is less than 0.1')
            }
          }, 0)
        })
      })

      describe('Array', function() {
        describe('#indexOf()', function() {
          it('should return -1 when the value is not present', function() {
            chai.assert.equal([1, 2, 3].indexOf(4), -1);
          });
        });
        
      });
      
      describe('#add', function() {
        it('should return 2 when 1 + 1', function() {
          chai.assert.equal(add(1, 1), 2);
        });
      });

      describe('#Learn chai assertion library', function () {
        describe('How to use should', function () {
          it('should', function () {
            chai.should();

            let foo = 'bar'
            let tea = {
              flavors: '123'
            }

            foo.should.be.a('string');
            foo.should.equal('bar');
            foo.should.have.lengthOf(3);
            tea.should.have.property('flavors').with.lengthOf(3);
          })
        })

        describe('How to use expect', function () {
          it('expect', function () {
            var expect = chai.expect;

            let foo = 'bar'
            let tea = {
              flavors: '1234'
            }

            expect(foo).to.be.a('string');
            expect(foo).to.equal('bar');
            expect(foo).to.have.lengthOf(3);
            expect(tea).to.have.property('flavors').with.lengthOf(3);
          })
        })
      })
      
      describe('#Custom assertion', function () {
        function equal (a, b, c) {
          if (a + b !== c) {
            throw new Error('err')
          }
        }
        it('1 + 1 = 2, but I passed 3.', function () {
          equal(1, 1, 3)
        })

        it('1 + 1 = 2', function () {
          equal(1, 1, 2)
        })
      })
    </script>

    <script class="mocha-exec">
      mocha.run();
    </script>
  </body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console