Jake Trent

Tag: Mocha

Testing React on jsdom

React allows you to create components that will render UI for your application. If your UI is of any complexity, you’ll likely want to test that it functions correctly and allows for future refactors. There are numerous ways to do this. One way that you might appreciate is using jsdom, an in-JavaScript implementation of the DOM.

Read more

Run a Single Mocha Test

When working inside your test suite, it’s often the case that you don’t want to run all of your tests. Mocha has a great mechanism that allows you to easily specify what exactly you want run. This can help make your processes such as TDD faster and more focused.

Read more

Mocha Testing AngularJs Dependency Injection

When you test your AngularJs code, you need to explicitly inject the services that your controllers and modules require. It has its own special syntax. It requires mocking. You’ll see a slightly different syntax than you may have expected.

Read more

Test RequireJs Code in Testacular

Did you write your source code as JavaScript AMD modules in RequireJs? Do you want to test them in real browsers? Do you want the flexibility of using Mocha or Jasmine? This is the moment you’ve been waiting for.

Testacular is a “spetacular test runner for JavaScript” that was written to support the AngularJs project. It is valuable because it will run your tests in real browsers. This is important for front-end code that relies on browser globals such as window (eg, if you use jQuery) or that manipulates the DOM (which could vary browser to browser).

Client-side JavaScript testing is a somewhat crazy space. Some have even called it “insane” and taken drastically different routes than what follows. But we’re gonna see if we can power through, and Testacular will help us get the job done.

Read more