UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

79 lines 3.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /// <reference path="./types/chai.d.ts"/> var _1 = require("../"); function isNodeOrFragment(thing) { // Using a simple `instanceof` check is intentionally avoided here to make // this code agnostic to a specific instance of a Schema. return thing && typeof thing.eq === 'function'; } function isSlice(thing) { return typeof thing.openStart === 'number' && typeof thing.openEnd === 'number' && isNodeOrFragment(thing.content); } exports.default = function (chai) { var Assertion = chai.Assertion, util = chai.util; // Node and Fragment Assertion.overwriteMethod('equal', function (equalSuper) { return function (right) { var left = this._obj; var deep = util.flag(this, 'deep'); if (deep && isNodeOrFragment(left) && isNodeOrFragment(right)) { this.assert(left.eq(right), "expected " + left.toString() + " to equal " + right.toString(), "expected " + left.toString() + " to not equal " + right.toString(), left.toJSON(), right.toJSON(), /*showDiff*/ true); } else { equalSuper.apply(this, arguments); } }; }); // Slice Assertion.overwriteMethod('equal', function (equalSuper) { return function (right) { var left = this._obj; var deep = util.flag(this, 'deep'); if (deep && isSlice(left) && isSlice(right)) { this.assert(left.content.eq(right.content), 'expected left\'s fragment #{exp} to equal right\'s fragment #{act}', 'expected left\'s fragment #{exp} to not equal right\'s fragment #{act}', left.content.toString(), right.content.toString()); this.assert(left.openStart === right.openStart, 'expected left\'s openStart #{exp} to equal right\'s openStart #{act}', 'expected left\'s openStart #{exp} to not equal right\'s openStart #{act}', left.openStart, right.openStart); this.assert(left.openEnd === right.openEnd, 'expected left\'s openEnd #{exp} to equal right\'s openEnd #{act}', 'expected left\'s openEnd #{exp} to not equal right\'s openEnd #{act}', left.openEnd, right.openEnd); } else { equalSuper.apply(this, arguments); } }; }); Assertion.addMethod('nodeType', function (nodeType) { var obj = util.flag(this, 'object'); var negate = util.flag(this, 'negate'); if (negate) { return new Assertion(obj.type).not.to.be.an.instanceof(nodeType); } return new Assertion(obj.type).to.be.an.instanceof(nodeType); }); Assertion.addMethod('textWithMarks', function (text, marks) { var obj = util.flag(this, 'object'); var negate = util.flag(this, 'negate'); var matched = false; obj.descendants(function (node, pos) { if (node.isText && node.text === text) { if (_1.Mark.sameSet(node.marks, marks)) { matched = true; } } }); if (negate) { return new Assertion(matched).not.to.be.true; } return new Assertion(matched).to.be.true; }); Assertion.addMethod('nodeSpec', function (nodeSpec) { var obj = util.flag(this, 'object'); var negate = util.flag(this, 'negate'); if (negate) { return new Assertion(obj.type.spec).not.to.deep.equal(nodeSpec); } return new Assertion(obj.type.spec).to.deep.equal(nodeSpec); }); }; //# sourceMappingURL=chai.js.map