How to use createIndent method in Jest

Best JavaScript code snippet using jest

js2svg.js

Source:js2svg.js Github

copy

Full Screen

...170 *171 * @return {String}172 */173JS2SVG.prototype.createCDATA = function(cdata) {174 return this.createIndent() +175 this.config.cdataStart +176 cdata +177 this.config.cdataEnd;178};179/**180 * Create element tag.181 *182 * @param {Object} data element object183 *184 * @return {String}185 */186JS2SVG.prototype.createElem = function(data) {187 // beautiful injection for obtaining SVG information :)188 if (189 data.isElem('svg') &&190 data.hasAttr('width') &&191 data.hasAttr('height')192 ) {193 this.width = data.attr('width').value;194 this.height = data.attr('height').value;195 }196 // empty element and short tag197 if (data.isEmpty()) {198 if (this.config.useShortTags) {199 return this.createIndent() +200 this.config.tagShortStart +201 data.elem +202 this.createAttrs(data) +203 this.config.tagShortEnd;204 } else {205 return this.createIndent() +206 this.config.tagShortStart +207 data.elem +208 this.createAttrs(data) +209 this.config.tagOpenEnd +210 this.config.tagCloseStart +211 data.elem +212 this.config.tagCloseEnd;213 }214 // non-empty element215 } else {216 var tagOpenStart = this.config.tagOpenStart,217 tagOpenEnd = this.config.tagOpenEnd,218 tagCloseStart = this.config.tagCloseStart,219 tagCloseEnd = this.config.tagCloseEnd,220 openIndent = this.createIndent(),221 textIndent = '',222 processedData = '',223 dataEnd = '';224 if (this.textContext) {225 tagOpenStart = defaults.tagOpenStart;226 tagOpenEnd = defaults.tagOpenEnd;227 tagCloseStart = defaults.tagCloseStart;228 tagCloseEnd = defaults.tagCloseEnd;229 openIndent = '';230 } else if (data.isElem(textElem)) {231 if (this.config.pretty) {232 textIndent += openIndent + this.config.indent;233 }234 this.textContext = data;235 }236 processedData += this.convert(data).data;237 if (this.textContext == data) {238 this.textContext = null;239 if (this.config.pretty) dataEnd = EOL;240 }241 return openIndent +242 tagOpenStart +243 data.elem +244 this.createAttrs(data) +245 tagOpenEnd +246 textIndent +247 processedData +248 dataEnd +249 this.createIndent() +250 tagCloseStart +251 data.elem +252 tagCloseEnd;253 }254};255/**256 * Create element attributes.257 *258 * @param {Object} elem attributes object259 *260 * @return {String}261 */262JS2SVG.prototype.createAttrs = function(elem) {263 var attrs = '';264 elem.eachAttr(function(attr) {265 if (attr.value !== undefined) {266 attrs += ' ' +267 attr.name +268 this.config.attrStart +269 String(attr.value).replace(this.config.regValEntities, this.config.encodeEntity) +270 this.config.attrEnd;271 }272 else {273 attrs += ' ' +274 attr.name;275 }276 }, this);277 return attrs;278};279/**280 * Create text node.281 *282 * @param {String} text text283 *284 * @return {String}285 */286JS2SVG.prototype.createText = function(text) {287 return this.createIndent() +288 this.config.textStart +289 text.replace(this.config.regEntities, this.config.encodeEntity) +290 (this.textContext ? '' : this.config.textEnd);...

Full Screen

Full Screen

rendering-lint.js

Source:rendering-lint.js Github

copy

Full Screen

...25 items.push("abc:" + listAbcElement(absEl.abcelem, 1));26 items.push(listAbsElement(absEl, 0));27 return items.join("\n");28}29function createIndent(indent) {30 var str = "";31 for (var i = 0; i < indent; i++)32 str += "\t";33 return str;34}35function listSvgElement(svgEl, indent) {36 var tab = createIndent(indent);37 var tab2 = createIndent(indent+1);38 var output = [];39 output.push("el: " + svgEl.tagName + listClasses(svgEl));40 switch (svgEl.tagName) {41 case "text":42 output.push("Text: " + svgEl.textContent);43 break;44 case "path":45 break;46 case "g":47 output.push("children: " + listGroupChildren(svgEl));48 break;49 default:50 console.log(svgEl.outerHTML)51 }52 return tab + output.join("\n"+tab2);53}54function listGroupChildren(g) {55 var output = [];56 for (var i = 0; i < g.children.length; i++) {57 var el = g.children[i];58 output.push(el.tagName + listClasses(el));59 }60 return output.join(" ");61}62function listAttributes(el, indent) {63 var tab = createIndent(indent);64 if (el.hasAttributes()) {65 var attrs = el.attributes;66 var output = [];67 for(var i = attrs.length - 1; i >= 0; i--) {68 if (attrs[i].name !== "class" && attrs[i].name !== "d")69 output.push(attrs[i].name + ": " + attrs[i].value);70 }71 output = output.sort();72 return "\n"+tab + output.join("\n"+tab);73 } else {74 return "";75 }76}77function listClasses(el) {78 var classes = el.classList;79 var klasses = [];80 for (var i = 0; i < classes.length; i++)81 klasses.push(classes[i]);82 klasses = klasses.sort();83 if (klasses.length === 0)84 return "[none]";85 return '.' + klasses.join(".");86}87function listAbsElement(absEl, indent) {88 var tab = createIndent(indent);89 var tab2 = createIndent(indent+1);90 var output = ["abs:"];91 var keys = Object.keys(absEl).sort();92 for (var i = 0; i < keys.length; i++) {93 var item = absEl[keys[i]];94 switch(keys[i]) {95 case "abcelem":96 case "highlight":97 case "unhighlight":98 break;99 case "elemset":100 // List this at the bottom101 break;102 case "specialY":103 var yVals = [];104 var yKeys = Object.keys(item).sort();105 for (var y = 0; y < yKeys.length; y++) {106 if (item[yKeys[y]] !== 0)107 yVals.push(yKeys[y] + "=" + item[yKeys[y]]);108 }109 if (yVals.length > 0)110 output.push(keys[i] + ": " + yVals.join(', '));111 break;112 case "beam":113 if (item.length > 0)114 console.log(keys[i], item);115 break;116 case "heads":117 case "extra":118 case "children":119 case "right":120 if (item.length > 0) {121 output.push(keys[i] + ":");122 for (var k = 0; k < item.length; k++) {123 output.push(listRelativeElement(item[k], indent + 1));124 }125 }126 break;127 case "tuneNumber":128 case "bottom":129 case "duration":130 case "durationClass":131 case "extraw":132 case "minspacing":133 case "top":134 case "type":135 case "w":136 case "x":137 output.push(keys[i] + ": " + item);138 break;139 case "invisible":140 case "isClef":141 // Don't clutter with false items142 if (item)143 output.push(keys[i] + ": " + item);144 break;145 default:146 if (item !== undefined)147 output.push(keys[i] + ": " + item);148 }149 }150 if (absEl.elemset) {151 item = absEl.elemset;152 output.push("elemset: (" + item.length + ")");153 for (var j = 0; j < item.length; j++) {154 output.push(listSvgElement(item[j], indent+1));155 }156 }157 return tab + output.join("\n"+tab2);158}159function listRelativeElement(relativeElement, indent) {160 var tab2 = createIndent(indent+1);161 var output = [];162 output.push("relative element: " + relativeElement.type);163 var keys = Object.keys(relativeElement).sort();164 for (var i = 0; i < keys.length; i++) {165 var item = relativeElement[keys[i]];166 switch (keys[i]) {167 case "parent":168 case "part":169 break;170 case "dim":171 output.push(keys[i] +": "+JSON.stringify(item.attr));172 break;173 case "graphelem":174 if (item) {175 output.push(keys[i] +": ");176 var svg = listSvgElement(item, indent+1);177 svg = svg.substring(indent); // Remove the indent on the first line because that will be added as the last line of this method.178 output.push(svg);179 }180 break;181 case "note":182 break;183 case "tempo":184 var tempoDetails = [];185 if (item.preString)186 tempoDetails.push("preString: " + item.preString);187 if (item.duration && item.duration.length)188 tempoDetails.push("duration: " + item.duration.join(","));189 if (item.bpm)190 tempoDetails.push("bpm: " + item.bpm);191 if (item.postString)192 tempoDetails.push("postString: " + item.postString);193 output.push(keys[i] + ": " + tempoDetails.join(", "));194 break;195 default:196 if (item !== undefined)197 output.push(keys[i] + ": " + (''+item).replace(/\n/g, "\\n"));198 break;199 }200 }201 return output.join("\n"+tab2);202}203function listAbcElement(abcelem, indent) {204 var tab = createIndent(indent);205 var output = [];206 var ignored = [];207 var keys = Object.keys(abcelem).sort();208 for (var i = 0; i < keys.length; i++) {209 var item = abcelem[keys[i]];210 switch(keys[i]) {211 case "el_type":212 case "startChar":213 case "endChar":214 case "text":215 case "type":216 case "verticalPos":217 case "clefPos":218 case "root":219 case "acc":220 case "mode":221 case "preString":222 case "postString":223 case "duration":224 case "bpm":225 case "title":226 case "decoration":227 case "averagepitch":228 case "minpitch":229 case "maxpitch":230 case "startBeam":231 case "endBeam":232 case "barNumber":233 case "endTriplet":234 case "startTriplet":235 case "tripletMultiplier":236 case "startEnding":237 case "endEnding":238 output.push(keys[i] + ": " + item);239 break;240 case "gracenotes":241 case "chord":242 case "rest":243 case "value":244 case "lyric":245 case "pitches":246 case "accidentals":247 output.push(listArrayOfObjects(keys[i], item, indent+1));248 break;249 case "abselem":250 break;251 default:252 ignored.push(keys[i]);253 console.log(keys[i] + ' ' + item)254 }255 }256 if (ignored.length > 0)257 output.push("ignored: " + ignored.join(" "));258 return "\n"+tab + output.join("\n"+tab);259}260function listArrayOfObjects(key, arr, indent) {261 var tab = createIndent(indent);262 var output = [];263 output.push(key + ":");264 for (var i = 0; i < arr.length; i++) {265 var item = arr[i];266 var keys = Object.keys(item).sort();267 for (var j = 0; j < keys.length; j++) {268 switch(keys[j]) {269 case "startSlur":270 case "startTie":271 output.push(listArrayOfObjects(keys[j], item[keys[j]], indent+1));272 break;273 default:274 output.push(keys[j] + ': ' + item[keys[j]]);275 }...

Full Screen

Full Screen

Jest Testing Tutorial

LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.

Chapters

  1. What is Jest Framework
  2. Advantages of Jest - Jest has 3,898,000 GitHub repositories, as mentioned on its official website. Learn what makes Jest special and why Jest has gained popularity among the testing and developer community.
  3. Jest Installation - All the prerequisites and set up steps needed to help you start Jest automation testing.
  4. Using Jest with NodeJS Project - Learn how to leverage Jest framework to automate testing using a NodeJS Project.
  5. Writing First Test for Jest Framework - Get started with code-based tutorial to help you write and execute your first Jest framework testing script.
  6. Jest Vocabulary - Learn the industry renowned and official jargons of the Jest framework by digging deep into the Jest vocabulary.
  7. Unit Testing with Jest - Step-by-step tutorial to help you execute unit testing with Jest framework.
  8. Jest Basics - Learn about the most pivotal and basic features which makes Jest special.
  9. Jest Parameterized Tests - Avoid code duplication and fasten automation testing with Jest using parameterized tests. Parameterization allows you to trigger the same test scenario over different test configurations by incorporating parameters.
  10. Jest Matchers - Enforce assertions better with the help of matchers. Matchers help you compare the actual output with the expected one. Here is an example to see if the object is acquired from the correct class or not. -

|<p>it('check_object_of_Car', () => {</p><p> expect(newCar()).toBeInstanceOf(Car);</p><p> });</p>| | :- |

  1. Jest Hooks: Setup and Teardown - Learn how to set up conditions which needs to be followed by the test execution and incorporate a tear down function to free resources after the execution is complete.
  2. Jest Code Coverage - Unsure there is no code left unchecked in your application. Jest gives a specific flag called --coverage to help you generate code coverage.
  3. HTML Report Generation - Learn how to create a comprehensive HTML report based on your Jest test execution.
  4. Testing React app using Jest Framework - Learn how to test your react web-application with Jest framework in this detailed Jest tutorial.
  5. Test using LambdaTest cloud Selenium Grid - Run your Jest testing script over LambdaTest cloud-based platform and leverage parallel testing to help trim down your test execution time.
  6. Snapshot Testing for React Front Ends - Capture screenshots of your react based web-application and compare them automatically for visual anomalies with the help of Jest tutorial.
  7. Bonus: Import ES modules with Jest - ES modules are also known as ECMAScript modules. Learn how to best use them by importing in your Jest testing scripts.
  8. Jest vs Mocha vs Jasmine - Learn the key differences between the most popular JavaScript-based testing frameworks i.e. Jest, Mocha, and Jasmine.
  9. Jest FAQs(Frequently Asked Questions) - Explore the most commonly asked questions around Jest framework, with their answers.

Run Jest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful