// tslint:disable:no-invalid-this import "jest"; import { Node } from "prosemirror-model"; import { ExpectExtendSync } from "./expect"; const matcherName = "toMatchNode"; const toMatchNode: ExpectExtendSync = function(received, expected) { if (!(expected instanceof Node)) { return { message: () => `${this.utils.matcherHint(`.${matcherName}`)}\n\n` + `Expected value should be an Node (using instanceof):\n` + ` ${this.utils.printExpected(expected)}`, pass: false }; } if (!(received instanceof Node)) { return { message: () => `${this.utils.matcherHint(`.${matcherName}`)}\n\n` + `Received value should be an Node (using instanceof):\n` + ` ${this.utils.printReceived(received)}`, pass: false }; } const pass = expected.eq(received); return { message: () => pass ? `${this.utils.matcherHint(`.not.${matcherName}`)}\n\n` + `Expected to not be (using .eq):\n` + ` ${this.utils.printExpected(expected)}\n` + `Received:\n` + ` ${this.utils.printReceived(received)}` : `${this.utils.matcherHint(`.${matcherName}`)}\n\n` + `Expected to be (using .eq):\n` + ` ${this.utils.printExpected(expected)}\n` + `Received:\n` + ` ${this.utils.printReceived(received)}`, pass }; }; declare global { namespace jest { interface Matchers { toMatchNode(expected: Node): R; } } } expect.extend({ toMatchNode });