This post is about raynor-chai, a nifty extension/helper for chai, the JavaScript assertions library. It allows one to use the methods of raynor to check that certain objects behave in the way you like.

Using it looks something like this:

import * as chai from 'chai'
import { raynorChai } from 'raynor-chai'

class User {
    name: string;
    scoresByDay: number[];

    totalScore(): number {
        return this.scoresByDay.reduce((a,b) => a + b, 0);


const user = new User(); = 'Raynor';
user.scoresByDay = [10, 20, 30];

chai.expect(user) (MarshalFrom(User))()); // Assertion passes

const badUser = new User(); = 'Raynor';
badUser.scoresByDay = [10, 20.5, 30];

chai.expect(badUSer) (MarshalFrom(User))()); // Assertion passes

Just like raynor it’s supposed to go beyond simple type checking you’d get from typescript and instead focus on deeper properties of objects. It’s especially useful to test that objects constructed as part of a larger processes are the way they’re supposed to be. So if you’re testing your REST API you can use the same entity definitions you’re using in your application code to see that the API does what it’s supposed to do and outputs the things it’s supposed to.

There’s just one release right now, but I’ll try to evolve it as I use it and as Raynor evolves itself.