Skip to content

Latest commit

 

History

History

javascript

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

JavaScript

JS Logo

We write a lot of JavaScript. As the Web continues to grow and as users expect more dynamic interaction with websites, JavaScript has taken on an increasingly large role. However, we believe that it's also important to know when not to use JavaScript. We prefer semantic HTML and CSS solutions whenever possible, and only reach for JavaScript to enhance these capabilities. We find that this approach helps to ensure that our work is accessible to the largest number of people possible.

Style

Consistent code styling helps our teams work together better and can help prevent common JavaScript pitfalls. We rely heavily on manual code reviews to ensure the quality and functionality of the code we're writing, but prefer to automate code style enforcement as much as possible. We use ESLint with a custom configuration to help enforce consistent code style.

Modern Code, Old Browsers

Browser support is a constantly moving target. While we like to be forward-thinking with our code, it's also important to remain backwards-compatible. We use Babel and Webpack, along with appropriate polyfills, to allow us to use the most modern and awesome features of JavaScript while supporting the widest range of browsers.

Static Types

We like the dynamic nature of JavaScript, but we also recognize the usefulness of static type checking. We like to use TypeScript when the need arises.

Frameworks / Libraries

JavaScript has a rich ecosystem of libraries. Here are some of the tools we like to use.

  • React - A view library for building user interfaces
  • Vue - Another view library for building user interfaces
  • Redux - A state management library
  • Axios - An isomorphic HTTP client
  • Lodash - A utility library packed full of useful functionality
  • Moment - A date/time library
  • Chartist - A responsive chart library

Testing

Automated testing is an important part of our development process. Here are some of the tools we use to test.

  • Mocha - A test runner
  • Chai - A test assertion library
  • Sinon - A test mocking library
  • jsdom - A Node.js implementation of various browser APIs, useful for testing DOM behavior
  • Enzyme - A utility for testing React components
  • Jest - Another test runner

Mocha vs Jest comparison

Mocha is a fast, highly-configurable test runner but does not provide assertions or mocking out of the box. At Sparkbox, we typically use a combination of Mocha + Chai + Sinon, rolling in jsdom or Enzyme when appropriate for component testing.

Jest, on the other hand, provides a complete "out of the box" testing solution, including assertions, mocking, and jsdom with zero configuration. The downside of Jest is that it can run significantly slower than Mocha, particularly with large test suites.

When choosing a test runner, a general guideline is

  • For speed and configurability, choose Mocha
  • For ease-of-use and developer experience, choose Jest