jbutz
10/30/2017 - 12:04 PM

jasonbutz.info - Custom Jest Except Matcher

jasonbutz.info - Custom Jest Except Matcher

class NullLikeMatcher {
    constructor() {
        this.$$typeof = Symbol.for('jest.asymmetricMatcher');
    }
    asymmetricMatch(value) {
        return value === null || value === undefined;
    }

    toString() {
        return 'NullLike';
    }

    toAsymmetricMatcher() {
        return 'NullLike';
    }
}

expect.nullLike = () => new NullLikeMatcher();