How to use normalize method in Jest

Best JavaScript code snippet using jest

NormalizeRangeTest.js

Source: NormalizeRangeTest.js Github

copy

Full Screen

...39 var ec = Hierarchy.follow(Element.fromDom(viewBlock.get()), endPath).getOrDie();40 var rng = document.createRange();41 rng.setStart(sc.dom(), startOffset);42 rng.setEnd(ec.dom(), endOffset);43 return NormalizeRange.normalize(new DOMUtils(document, { root_element: viewBlock.get() }), rng);44 });45 };46 var cAssertRange = function (startPath, startOffset, endPath, endOffset) {47 return Chain.op(function (range) {48 assertRange(viewBlock.get(), range, startPath, startOffset, endPath, endOffset);49 });50 };51 var cAssertRangeNone = Chain.op(function (range) {52 Assertions.assertEq('Should be none', true, range.isNone());53 });54 viewBlock.attach();55 Pipeline.async({}, [56 Logger.t('Non normalize non collapsed selections', GeneralSteps.sequence([57 Logger.t('Should not normalize on indexed selected at root level', Chain.asStep(viewBlock, [58 cSetHtml('<input>'),59 cNormalizeRange([], 0, [], 1),60 cAssertRangeNone61 ])),62 Logger.t('Should not normalize if selection is around a caret container', Chain.asStep(viewBlock, [63 cSetHtml('<p data-mce-caret="before">b</​p>'),64 cNormalizeRange([], 0, [], 1),65 cAssertRangeNone66 ])),67 Logger.t('Should not normalize if selection ends after table', Chain.asStep(viewBlock, [68 cSetHtml('<p>a</​p><table><tr><td>b</​td></​tr></​table>'),69 cNormalizeRange([0, 0], 0, [], 2),70 cAssertRangeNone71 ])),72 Logger.t('Should not normalize into pre', Chain.asStep(viewBlock, [73 cSetHtml('<pre>a</​pre>'),74 cNormalizeRange([], 0, [], 1),75 cAssertRangeNone76 ])),77 Logger.t('Should not normalize to before/​after table', Chain.asStep(viewBlock, [78 cSetHtml('<table><tr><td>a</​td></​tr></​table>'),79 cNormalizeRange([], 0, [], 1),80 cAssertRangeNone81 ]))82 ])),83 Logger.t('Non normalize caret positions', GeneralSteps.sequence([84 Logger.t('Should not normalize on a caret at start of text node', Chain.asStep(viewBlock, [85 cSetHtml('<p>a</​p>'),86 cNormalizeRange([0, 0], 0, [0, 0], 0),87 cAssertRangeNone88 ])),89 Logger.t('Should not normalize on a caret at middle of text node', Chain.asStep(viewBlock, [90 cSetHtml('<p>a</​p>'),91 cNormalizeRange([0, 0], 1, [0, 0], 1),92 cAssertRangeNone93 ])),94 Logger.t('Should not normalize on a caret at end of text node', Chain.asStep(viewBlock, [95 cSetHtml('<p>a</​p>'),96 cNormalizeRange([0, 0], 1, [0, 0], 1),97 cAssertRangeNone98 ])),99 Logger.t('Should not normalize on a caret before input', Chain.asStep(viewBlock, [100 cSetHtml('<p><input></​p>'),101 cNormalizeRange([0], 0, [0], 0),102 cAssertRangeNone103 ])),104 Logger.t('Should not normalize on a caret between inputs', Chain.asStep(viewBlock, [105 cSetHtml('<p><input><input></​p>'),106 cNormalizeRange([0], 1, [0], 1),107 cAssertRangeNone108 ])),109 Logger.t('Should not normalize on a caret after input', Chain.asStep(viewBlock, [110 cSetHtml('<p><input></​p>'),111 cNormalizeRange([0], 1, [0], 1),112 cAssertRangeNone113 ])),114 Logger.t('Should not normalize on a caret after image', Chain.asStep(viewBlock, [115 cSetHtml('<p><img src="about: blank"></​p>'),116 cNormalizeRange([0], 1, [0], 1),117 cAssertRangeNone118 ])),119 Logger.t('Should not normalize on a caret before image', Chain.asStep(viewBlock, [120 cSetHtml('<p><img src="about: blank"></​p>'),121 cNormalizeRange([0], 0, [0], 0),122 cAssertRangeNone123 ])),124 Logger.t('Should not normalize before br', Chain.asStep(viewBlock, [125 cSetHtml('<p><br></​p>'),126 cNormalizeRange([0], 0, [0], 0),127 cAssertRangeNone128 ])),129 Logger.t('Should not normalize into previous block with format', Chain.asStep(viewBlock, [130 cSetHtml('<div><p><b>a</​b></​p>b</​p>'),131 cNormalizeRange([0, 1], 0, [0, 1], 0),132 cAssertRangeNone133 ])),134 Logger.t('Should not normalize into previous format inline with input', Chain.asStep(viewBlock, [135 cSetHtml('<p><b><input></​b>b</​p>'),136 cNormalizeRange([0, 1], 0, [0, 1], 0),137 cAssertRangeNone138 ])),139 Logger.t('Should not normalize into previous cef inline', Chain.asStep(viewBlock, [140 cSetHtml('<p><b contenteditable="false">a</​b>b</​p>'),141 cNormalizeRange([0, 1], 0, [0, 1], 0),142 cAssertRangeNone143 ])),144 Logger.t('Should not normalize into cef block', Chain.asStep(viewBlock, [145 cSetHtml('<p contenteditable="false">a</​p>'),146 cNormalizeRange([], 0, [], 0),147 cAssertRangeNone148 ])),149 Logger.t('Should not normalize into previous anchor inline', Chain.asStep(viewBlock, [150 cSetHtml('<p><a href="#">a</​a>b</​p>'),151 cNormalizeRange([0, 1], 0, [0, 1], 0),152 cAssertRangeNone153 ])),154 Logger.t('Should not normalize out of a caret container', Chain.asStep(viewBlock, [155 cSetHtml('<p><b>a</​b><span data-mce-caret="before">b</​span></​p>'),156 cNormalizeRange([0, 1, 0], 0, [0, 1, 0], 0),157 cAssertRangeNone158 ])),159 Logger.t('Should not normalize out of a caret container', Chain.asStep(viewBlock, [160 cSetHtml('<p><b>a</​b>' + Zwsp.ZWSP + '</​p>'),161 cNormalizeRange([0, 1], 0, [0, 1], 0),162 cAssertRangeNone163 ])),164 Logger.t('Should not normalize when caret is at start of text node', Chain.asStep(viewBlock, [165 cSetHtml('a'),166 cNormalizeRange([0], 0, [0], 0),167 cAssertRangeNone168 ])),169 Logger.t('Should not normalize when caret is at end of text node', Chain.asStep(viewBlock, [170 cSetHtml('a'),171 cNormalizeRange([0], 1, [0], 1),172 cAssertRangeNone173 ])),174 Logger.t('Should not normalize when caret is at middle of text node', Chain.asStep(viewBlock, [175 cSetHtml('ab'),176 cNormalizeRange([0], 1, [0], 1),177 cAssertRangeNone178 ])),179 Logger.t('Should not normalize when caret is before text node', Chain.asStep(viewBlock, [180 cSetHtml('a'),181 cNormalizeRange([], 0, [], 0),182 cAssertRangeNone183 ])),184 Logger.t('Should not normalize when caret is after text node', Chain.asStep(viewBlock, [185 cSetHtml('a'),186 cNormalizeRange([], 1, [], 1),187 cAssertRangeNone188 ])),189 Logger.t('Should not normalize into inline elements if target inline pos is a br', Chain.asStep(viewBlock, [190 cSetHtml('<p><i><b><br /​></​b></​i><br /​></​p>'),191 cNormalizeRange([0], 1, [0], 1),192 cAssertRangeNone193 ])),194 Logger.t('Should not normalize from after double br', Chain.asStep(viewBlock, [195 cSetHtml('<p>a<br /​><br /​></​p>'),196 cNormalizeRange([0], 3, [0], 3),197 cAssertRangeNone198 ])),199 Logger.t('Should not normalize into first text node', Chain.asStep(viewBlock, [200 cSetHtml('a<b>b</​b>c'),201 cNormalizeRange([], 0, [], 0),202 cAssertRangeNone203 ])),204 Logger.t('Should not normalize into last text node', Chain.asStep(viewBlock, [205 cSetHtml('a<b>b</​b>c'),206 cNormalizeRange([], 3, [], 3),207 cAssertRangeNone208 ]))209 ])),210 Logger.t('Normalize caret positions', GeneralSteps.sequence([211 Logger.t('Should normalize caret and lean left from text node into previous inline element text node', Chain.asStep(viewBlock, [212 cSetHtml('<p><b>a</​b>b</​p>'),213 cNormalizeRange([0, 1], 0, [0, 1], 0),214 cAssertRange([0, 0, 0], 1, [0, 0, 0], 1)215 ])),216 Logger.t('Should normalize caret and lean left from text node into previous text node', Chain.asStep(viewBlock, [217 cSetHtml('<p>a<b>b</​b></​p>'),218 cNormalizeRange([0, 1, 0], 0, [0, 1, 0], 0),219 cAssertRange([0, 0], 1, [0, 0], 1)220 ])),221 Logger.t('Should normalize caret and lean left from inline element text node into previous inline element text node', Chain.asStep(viewBlock, [222 cSetHtml('<p><b>a</​b><i>b</​i></​p>'),223 cNormalizeRange([0, 1, 0], 0, [0, 1, 0], 0),224 cAssertRange([0, 0, 0], 1, [0, 0, 0], 1)225 ])),226 Logger.t('Should normalize caret and lean left from before br in inline element into previous inline element text node', Chain.asStep(viewBlock, [227 cSetHtml('<p><b>a</​b><i><br></​i></​p>'),228 cNormalizeRange([0, 1], 0, [0, 1], 0),229 cAssertRange([0, 0, 0], 1, [0, 0, 0], 1)230 ])),231 Logger.t('Should normalize on a caret between blocks', Chain.asStep(viewBlock, [232 cSetHtml('<p>a</​p><p>b</​p>'),233 cNormalizeRange([], 1, [], 1),234 cAssertRange([1, 0], 0, [1, 0], 0)235 ])),236 Logger.t('Should normalize from after br to before br', Chain.asStep(viewBlock, [237 cSetHtml('<p><br /​></​p>'),238 cNormalizeRange([0], 1, [0], 1),239 cAssertRange([0], 0, [0], 0)240 ])),241 Logger.t('Should normalize from after br to before br', Chain.asStep(viewBlock, [242 cSetHtml('<p>a<br /​></​p>'),243 cNormalizeRange([0], 1, [0], 1),244 cAssertRange([0, 0], 1, [0, 0], 1)245 ])),246 Logger.t('Should normalize before paragraph', Chain.asStep(viewBlock, [247 cSetHtml('<p>a</​p>'),248 cNormalizeRange([], 0, [], 0),249 cAssertRange([0, 0], 0, [0, 0], 0)250 ])),251 Logger.t('Should normalize after paragraph', Chain.asStep(viewBlock, [252 cSetHtml('<p>a</​p>'),253 cNormalizeRange([], 1, [], 1),254 cAssertRange([0, 0], 1, [0, 0], 1)255 ])),256 Logger.t('Should normalize into caret container', Chain.asStep(viewBlock, [257 cSetHtml('<p><span id="_mce_caret">' + Zwsp.ZWSP + '</​span><br /​></​p>'),258 cNormalizeRange([0], 1, [0], 1),259 cAssertRange([0, 0, 0], 1, [0, 0, 0], 1)260 ])),261 Logger.t('Should normalize into empty inline element before', Chain.asStep(viewBlock, [262 cSetHtml('<p><i><b></​b></​i><br /​></​p>'),263 cNormalizeRange([0], 1, [0], 1),264 cAssertRange([0, 0, 0], 0, [0, 0, 0], 0)265 ]))266 ])),267 Logger.t('Normalize expanded selections', GeneralSteps.sequence([268 Logger.t('Should normalize to before/​after image', Chain.asStep(viewBlock, [269 cSetHtml('<p><img src="about:blank "></​p>'),270 cNormalizeRange([], 0, [], 1),271 cAssertRange([0], 0, [0], 1)272 ])),273 Logger.t('Should normalize to text node in p', Chain.asStep(viewBlock, [274 cSetHtml('<p>a</​p>'),275 cNormalizeRange([], 0, [], 1),276 cAssertRange([0, 0], 0, [0, 0], 1)277 ])),278 Logger.t('Should normalize to text node in middle p', Chain.asStep(viewBlock, [279 cSetHtml('<p>a</​p><p>b</​p><p>c</​p>'),280 cNormalizeRange([], 1, [], 2),281 cAssertRange([1, 0], 0, [1, 0], 1)282 ])),283 Logger.t('Should normalize start from end of inline to start of next inline element', Chain.asStep(viewBlock, [284 cSetHtml('<p><b>a</​b><i>b</​i></​p>'),285 cNormalizeRange([0, 0, 0], 1, [0, 1, 0], 1),286 cAssertRange([0, 1, 0], 0, [0, 1, 0], 1)287 ]))288 ])),289 Logger.t('Normalize on document', Step.sync(function () {290 var doc = document.implementation.createHTMLDocument('');291 var rng = document.createRange();292 var dom = new DOMUtils(doc, { root_element: doc.body });293 doc.body.innerHTML = '<p>a</​p>';294 rng.setStart(document, 0);295 rng.setEnd(document, 0);296 var normRng = NormalizeRange.normalize(dom, rng);297 assertRange(doc.body, normRng, [0, 0], 0, [0, 0], 0);298 }))299 ], function () {300 viewBlock.detach();301 success();302 }, failure);303 }...

Full Screen

Full Screen

normalizeColor-test.js

Source: normalizeColor-test.js Github

copy

Full Screen

1/​**2 * Copyright (c) 2015-present, Facebook, Inc.3 * All rights reserved.4 *5 * This source code is licensed under the BSD-style license found in the6 * LICENSE file in the root directory of this source tree. An additional grant7 * of patent rights can be found in the PATENTS file in the same directory.8 */​9'use strict';10var normalizeColor = require('normalizeColor');11describe('normalizeColor', function() {12 it('should accept only spec compliant colors', function() {13 expect(normalizeColor('#abc')).not.toBe(null);14 expect(normalizeColor('#abcd')).not.toBe(null);15 expect(normalizeColor('#abcdef')).not.toBe(null);16 expect(normalizeColor('#abcdef01')).not.toBe(null);17 expect(normalizeColor('rgb(1,2,3)')).not.toBe(null);18 expect(normalizeColor('rgb(1, 2, 3)')).not.toBe(null);19 expect(normalizeColor('rgb( 1 , 2 , 3 )')).not.toBe(null);20 expect(normalizeColor('rgb(-1, -2, -3)')).not.toBe(null);21 expect(normalizeColor('rgba(0, 0, 0, 1)')).not.toBe(null);22 expect(normalizeColor(0x01234567 + 0.5)).toBe(null);23 expect(normalizeColor(-1)).toBe(null);24 expect(normalizeColor(0xffffffff + 1)).toBe(null);25 });26 it('should temporarly accept floating point values for rgb', function() {27 expect(normalizeColor('rgb(1.1, 2.1, 3.1)')).toBe(0x010203ff);28 expect(normalizeColor('rgba(1.1, 2.1, 3.1, 1.0)')).toBe(0x010203ff);29 });30 it('should refuse non spec compliant colors', function() {31 expect(normalizeColor('#00gg00')).toBe(null);32 expect(normalizeColor('rgb(1, 2, 3,)')).toBe(null);33 expect(normalizeColor('rgb(1, 2, 3')).toBe(null);34 /​/​ Used to be accepted by normalizeColor35 expect(normalizeColor('abc')).toBe(null);36 expect(normalizeColor(' #abc ')).toBe(null);37 expect(normalizeColor('##abc')).toBe(null);38 expect(normalizeColor('rgb 255 0 0')).toBe(null);39 expect(normalizeColor('RGBA(0, 1, 2)')).toBe(null);40 expect(normalizeColor('rgb (0, 1, 2)')).toBe(null);41 expect(normalizeColor('hsv(0, 1, 2)')).toBe(null);42 expect(normalizeColor({r: 10, g: 10, b: 10})).toBe(null);43 expect(normalizeColor('hsl(1%, 2, 3)')).toBe(null);44 expect(normalizeColor('rgb(1%, 2%, 3%)')).toBe(null);45 });46 it('should handle hex6 properly', function() {47 expect(normalizeColor('#000000')).toBe(0x000000ff);48 expect(normalizeColor('#ffffff')).toBe(0xffffffff);49 expect(normalizeColor('#ff00ff')).toBe(0xff00ffff);50 expect(normalizeColor('#abcdef')).toBe(0xabcdefff);51 expect(normalizeColor('#012345')).toBe(0x012345ff);52 });53 it('should handle hex3 properly', function() {54 expect(normalizeColor('#000')).toBe(0x000000ff);55 expect(normalizeColor('#fff')).toBe(0xffffffff);56 expect(normalizeColor('#f0f')).toBe(0xff00ffff);57 });58 it('should handle hex8 properly', function() {59 expect(normalizeColor('#00000000')).toBe(0x00000000);60 expect(normalizeColor('#ffffffff')).toBe(0xffffffff);61 expect(normalizeColor('#ffff00ff')).toBe(0xffff00ff);62 expect(normalizeColor('#abcdef01')).toBe(0xabcdef01);63 expect(normalizeColor('#01234567')).toBe(0x01234567);64 });65 it('should handle rgb properly', function() {66 expect(normalizeColor('rgb(0, 0, 0)')).toBe(0x000000ff);67 expect(normalizeColor('rgb(-1, -2, -3)')).toBe(0x000000ff);68 expect(normalizeColor('rgb(0, 0, 255)')).toBe(0x0000ffff);69 expect(normalizeColor('rgb(100, 15, 69)')).toBe(0x640f45ff);70 expect(normalizeColor('rgb(255, 255, 255)')).toBe(0xffffffff);71 expect(normalizeColor('rgb(256, 256, 256)')).toBe(0xffffffff);72 });73 it('should handle rgba properly', function() {74 expect(normalizeColor('rgba(0, 0, 0, 0.0)')).toBe(0x00000000);75 expect(normalizeColor('rgba(0, 0, 0, 0)')).toBe(0x00000000);76 expect(normalizeColor('rgba(0, 0, 0, -0.5)')).toBe(0x00000000);77 expect(normalizeColor('rgba(0, 0, 0, 1.0)')).toBe(0x000000ff);78 expect(normalizeColor('rgba(0, 0, 0, 1)')).toBe(0x000000ff);79 expect(normalizeColor('rgba(0, 0, 0, 1.5)')).toBe(0x000000ff);80 expect(normalizeColor('rgba(100, 15, 69, 0.5)')).toBe(0x640f4580);81 });82 it('should handle hsl properly', function() {83 expect(normalizeColor('hsl(0, 0%, 0%)')).toBe(0x000000ff);84 expect(normalizeColor('hsl(360, 100%, 100%)')).toBe(0xffffffff);85 expect(normalizeColor('hsl(180, 50%, 50%)')).toBe(0x40bfbfff);86 expect(normalizeColor('hsl(540, 50%, 50%)')).toBe(0x40bfbfff);87 expect(normalizeColor('hsl(70, 25%, 75%)')).toBe(0xcacfafff);88 expect(normalizeColor('hsl(70, 100%, 75%)')).toBe(0xeaff80ff);89 expect(normalizeColor('hsl(70, 110%, 75%)')).toBe(0xeaff80ff);90 expect(normalizeColor('hsl(70, 0%, 75%)')).toBe(0xbfbfbfff);91 expect(normalizeColor('hsl(70, -10%, 75%)')).toBe(0xbfbfbfff);92 });93 it('should handle hsla properly', function() {94 expect(normalizeColor('hsla(0, 0%, 0%, 0)')).toBe(0x00000000);95 expect(normalizeColor('hsla(360, 100%, 100%, 1)')).toBe(0xffffffff);96 expect(normalizeColor('hsla(360, 100%, 100%, 0)')).toBe(0xffffff00);97 expect(normalizeColor('hsla(180, 50%, 50%, 0.2)')).toBe(0x40bfbf33);98 });99 it('should handle named colors properly', function() {100 expect(normalizeColor('red')).toBe(0xff0000ff);101 expect(normalizeColor('transparent')).toBe(0x00000000);102 expect(normalizeColor('peachpuff')).toBe(0xffdab9ff);103 });104 it('should handle number colors properly', function() {105 expect(normalizeColor(0x00000000)).toBe(0x00000000);106 expect(normalizeColor(0xff0000ff)).toBe(0xff0000ff);107 expect(normalizeColor(0xffffffff)).toBe(0xffffffff);108 expect(normalizeColor(0x01234567)).toBe(0x01234567);109 });110 it('should return the same color when it\'s already normalized', function() {111 const normalizedColor = normalizeColor('red') || 0;112 expect(normalizeColor(normalizedColor)).toBe(normalizedColor);113 });...

Full Screen

Full Screen

jquery.sap.unicode.qunit.js

Source: jquery.sap.unicode.qunit.js Github

copy

Full Screen

...46 QUnit.test("reference data", function(assert) {47 assert.expect(8);48 jQuery.each(aData, function(i, o) {49 assert.equal(toCharCodes(o.string), o.representation, "\"" + o.form + "\"" + " string is valid");50 assert.equal(o.string.normalize(o.form), o.string, "\"" + o.form + "\"" + " string is \"" + o.form + "\"" );51 });52 });53 jQuery.each(aData, function(i, o) {54 QUnit.module(o.form, {55 beforeEach: function() {56 this.s = aData[0].string + aData[1].string + aData[2].string + aData[3].string;57 }58 });59 /​/​ ref: http:/​/​unicode.org/​reports/​tr15/​#Design_Goals60 QUnit.test("chaining", function(assert) {61 o.compatible ? assert.expect(6) : assert.expect(2);62 /​/​ primitive value of the normalized string as reference63 var sRef = this.s.normalize(o.form).valueOf();64 assert.equal(this.s.normalize("NFC").normalize(o.form), sRef, "\"NFC\"");65 assert.equal(this.s.normalize("NFD").normalize(o.form), sRef, "\"NFD\"");66 if (o.compatible) {67 /​/​ compatibility normalizations68 assert.equal(this.s.normalize("NFKC").normalize(o.form), sRef, "\"NFKC\"");69 assert.equal(this.s.normalize("NFKD").normalize(o.form), sRef, "\"NFKD\"");70 /​/​ and corresponding standard normalization71 assert.equal(this.s.normalize("NFKC").normalize(o.form.replace("K","")), sRef, "\"NFKC\"");72 assert.equal(this.s.normalize("NFKD").normalize(o.form.replace("K","")), sRef, "\"NFKD\"");73 }74 });75 });76 }77 /​/​ do not perform tests on mobiles without native support78 if (!Device.browser.mobile || String.prototype.normalize) {79 QUnit.module("Quick check NFC", {80 beforeEach: function() {81 /​/​ blind test, no relevant characters82 this.sBlind = "ABC";83 /​/​ some random combined characters84 this.sSomething = "Améliè";85 /​/​ all forms different character86 this.sNFC = "\u1E9B\u0323";87 this.sNFC = "\u1E9B\u0323";88 this.sNFD = "\u017F\u0323\u0307";89 this.sNFKC = "\u1E69";90 this.sNFKD = "\u0073\u0323\u0307";91 this.s = this.sNFC + this.sNFD + this.sNFKC + this.sNFKD;92 },93 afterEach: function() {}94 });95 QUnit.test("verify test string", function(assert) {96 assert.equal(this.sBlind, this.sBlind.normalize("NFC"), "NFC verified");97 assert.equal(this.sSomething, this.sSomething.normalize("NFC"), "NFC verified");98 assert.equal(this.sNFC, this.sNFC.normalize("NFC"), "NFC verified");99 assert.equal(this.sNFD, this.sNFD.normalize("NFD"), "NFD verified");100 assert.equal(this.sNFKC, this.sNFKC.normalize("NFKC"), "NFKC verified");101 assert.equal(this.sNFKD, this.sNFKD.normalize("NFKD"), "NFKD verified");102 assert.notEqual(this.s, this.s.normalize("NFC"), "not NFC verified");103 assert.notEqual(this.s, this.s.normalize("NFD"), "not NFD verified");104 assert.notEqual(this.s, this.s.normalize("NFKC"), "not NFKC verified");105 assert.notEqual(this.s, this.s.normalize("NFKD"), "not NFKD verified");106 assert.equal(this.sNFC + this.sNFC + this.sNFKC + this.sNFKC, this.s.normalize("NFC"), "NFC concatenation verified");107 assert.equal(this.sNFD + this.sNFD + this.sNFKD + this.sNFKD, this.s.normalize("NFD"), "NFD concatenation verified");108 assert.equal(this.sNFKC + this.sNFKC + this.sNFKC + this.sNFKC, this.s.normalize("NFKC"), "NFKC concatenation verified");109 assert.equal(this.sNFKD + this.sNFKD + this.sNFKD + this.sNFKD, this.s.normalize("NFKD"), "NFKD concatenation verified");110 });111 QUnit.test("isStringNFC", function(assert) {112 assert.ok(jQuery.sap.isStringNFC("ABC"), "NFC is NFC");113 assert.ok(jQuery.sap.isStringNFC("Améliè"), "NFC is NFC");114 assert.ok(!jQuery.sap.isStringNFC(this.sNFC) || jQuery.sap.isStringNFC(this.sNFC), "NFC maybe NFC");115 assert.ok(!jQuery.sap.isStringNFC(this.sNFD), "NFD is not NFC");116 assert.ok(jQuery.sap.isStringNFC(this.sNFKC), "NFKC is also NFC");117 assert.ok(!jQuery.sap.isStringNFC(this.sNFKD), "NFKD is not NFC");118 assert.ok(!jQuery.sap.isStringNFC(this.s), "concatenation is not NFC");119 });120 }...

Full Screen

Full Screen

normalize-generateddata.js

Source: normalize-generateddata.js Github

copy

Full Screen

...23 var nfdStr = stringify(test.NFD);24 var nfkcStr = stringify(test.NFKC);25 var nfkdStr = stringify(test.NFKD);26 /​* NFC */​27 assertEq(source.normalize(), NFC, "NFC of " + sourceStr);28 assertEq(NFC.normalize(), NFC, "NFC of " + nfcStr);29 assertEq(NFD.normalize(), NFC, "NFC of " + nfdStr);30 assertEq(NFKC.normalize(), NFKC, "NFC of " + nfkcStr);31 assertEq(NFKD.normalize(), NFKC, "NFC of " + nfkdStr);32 assertEq(source.normalize(undefined), NFC, "NFC of " + sourceStr);33 assertEq(NFC.normalize(undefined), NFC, "NFC of " + nfcStr);34 assertEq(NFD.normalize(undefined), NFC, "NFC of " + nfdStr);35 assertEq(NFKC.normalize(undefined), NFKC, "NFC of " + nfkcStr);36 assertEq(NFKD.normalize(undefined), NFKC, "NFC of " + nfkdStr);37 assertEq(source.normalize("NFC"), NFC, "NFC of " + sourceStr);38 assertEq(NFC.normalize("NFC"), NFC, "NFC of " + nfcStr);39 assertEq(NFD.normalize("NFC"), NFC, "NFC of " + nfdStr);40 assertEq(NFKC.normalize("NFC"), NFKC, "NFC of " + nfkcStr);41 assertEq(NFKD.normalize("NFC"), NFKC, "NFC of " + nfkdStr);42 /​* NFD */​43 assertEq(source.normalize("NFD"), NFD, "NFD of " + sourceStr);44 assertEq(NFC.normalize("NFD"), NFD, "NFD of " + nfcStr);45 assertEq(NFD.normalize("NFD"), NFD, "NFD of " + nfdStr);46 assertEq(NFKC.normalize("NFD"), NFKD, "NFD of " + nfkcStr);47 assertEq(NFKD.normalize("NFD"), NFKD, "NFD of " + nfkdStr);48 /​* NFKC */​49 assertEq(source.normalize("NFKC"), NFKC, "NFKC of " + sourceStr);50 assertEq(NFC.normalize("NFKC"), NFKC, "NFKC of " + nfcStr);51 assertEq(NFD.normalize("NFKC"), NFKC, "NFKC of " + nfdStr);52 assertEq(NFKC.normalize("NFKC"), NFKC, "NFKC of " + nfkcStr);53 assertEq(NFKD.normalize("NFKC"), NFKC, "NFKC of " + nfkdStr);54 /​* NFKD */​55 assertEq(source.normalize("NFKD"), NFKD, "NFKD of " + sourceStr);56 assertEq(NFC.normalize("NFKD"), NFKD, "NFKD of " + nfcStr);57 assertEq(NFD.normalize("NFKD"), NFKD, "NFKD of " + nfdStr);58 assertEq(NFKC.normalize("NFKD"), NFKD, "NFKD of " + nfkcStr);59 assertEq(NFKD.normalize("NFKD"), NFKD, "NFKD of " + nfkdStr);60}61for (var test0 of tests_part0) {62 runTest(test0);63}64var part1 = new Set();65for (var test1 of tests_part1) {66 part1.add(test1.source[0]);67 runTest(test1);68}69for (var test2 of tests_part2) {70 runTest(test2);71}72for (var test3 of tests_part3) {73 runTest(test3);74}75/​* not listed in Part 1 */​76for (var x = 0; x <= 0x2FFFF; x++) {77 if (part1.has(x)) {78 continue;79 }80 var xstr = x.toString(16);81 var c = String.fromCodePoint(x);82 assertEq(c.normalize(), c, "NFC of " + xstr);83 assertEq(c.normalize(undefined), c, "NFC of " + xstr);84 assertEq(c.normalize("NFC"), c, "NFC of " + xstr);85 assertEq(c.normalize("NFD"), c, "NFD of " + xstr);86 assertEq(c.normalize("NFKC"), c, "NFKC of " + xstr);87 assertEq(c.normalize("NFKD"), c, "NFKD of " + xstr);88}89var myobj = {toString : (function () "a\u0301"), normalize : String.prototype.normalize};90assertEq(myobj.normalize(), "\u00E1");91assertThrowsInstanceOf(function() {92 "abc".normalize("NFE");93 }, RangeError,94 "String.prototype.normalize should raise RangeError on invalid form");95assertEq("".normalize(), "");96/​* JSRope test */​97var a = "";98var b = "";99for (var i = 0; i < 100; i++) {100 a += "\u0100";101 b += "\u0041\u0304";102}103assertEq(a.normalize("NFD"), b);104/​******************************************************************************/​105if (typeof reportCompare === "function")106 reportCompare(true, true);...

Full Screen

Full Screen

test-path-normalize.js

Source: test-path-normalize.js Github

copy

Full Screen

1'use strict';2require('../​common');3const assert = require('assert');4const path = require('path');5assert.strictEqual(path.win32.normalize('./​fixtures/​/​/​b/​../​b/​c.js'),6 'fixtures\\b\\c.js');7assert.strictEqual(path.win32.normalize('/​foo/​../​../​../​bar'), '\\bar');8assert.strictEqual(path.win32.normalize('a/​/​b/​/​../​b'), 'a\\b');9assert.strictEqual(path.win32.normalize('a/​/​b/​/​./​c'), 'a\\b\\c');10assert.strictEqual(path.win32.normalize('a/​/​b/​/​.'), 'a\\b');11assert.strictEqual(path.win32.normalize('/​/​server/​share/​dir/​file.ext'),12 '\\\\server\\share\\dir\\file.ext');13assert.strictEqual(path.win32.normalize('/​a/​b/​c/​../​../​../​x/​y/​z'), '\\x\\y\\z');14assert.strictEqual(path.win32.normalize('C:'), 'C:.');15assert.strictEqual(path.win32.normalize('C:..\\abc'), 'C:..\\abc');16assert.strictEqual(path.win32.normalize('C:..\\..\\abc\\..\\def'),17 'C:..\\..\\def');18assert.strictEqual(path.win32.normalize('C:\\.'), 'C:\\');19assert.strictEqual(path.win32.normalize('file:stream'), 'file:stream');20assert.strictEqual(path.win32.normalize('bar\\foo..\\..\\'), 'bar\\');21assert.strictEqual(path.win32.normalize('bar\\foo..\\..'), 'bar');22assert.strictEqual(path.win32.normalize('bar\\foo..\\..\\baz'), 'bar\\baz');23assert.strictEqual(path.win32.normalize('bar\\foo..\\'), 'bar\\foo..\\');24assert.strictEqual(path.win32.normalize('bar\\foo..'), 'bar\\foo..');25assert.strictEqual(path.win32.normalize('..\\foo..\\..\\..\\bar'),26 '..\\..\\bar');27assert.strictEqual(path.win32.normalize('..\\...\\..\\.\\...\\..\\..\\bar'),28 '..\\..\\bar');29assert.strictEqual(path.win32.normalize('../​../​../​foo/​../​../​../​bar'),30 '..\\..\\..\\..\\..\\bar');31assert.strictEqual(path.win32.normalize('../​../​../​foo/​../​../​../​bar/​../​../​'),32 '..\\..\\..\\..\\..\\..\\');33assert.strictEqual(34 path.win32.normalize('../​foobar/​barfoo/​foo/​../​../​../​bar/​../​../​'),35 '..\\..\\'36);37assert.strictEqual(38 path.win32.normalize('../​.../​../​foobar/​../​../​../​bar/​../​../​baz'),39 '..\\..\\..\\..\\baz'40);41assert.strictEqual(path.win32.normalize('foo/​bar\\baz'), 'foo\\bar\\baz');42assert.strictEqual(path.posix.normalize('./​fixtures/​/​/​b/​../​b/​c.js'),43 'fixtures/​b/​c.js');44assert.strictEqual(path.posix.normalize('/​foo/​../​../​../​bar'), '/​bar');45assert.strictEqual(path.posix.normalize('a/​/​b/​/​../​b'), 'a/​b');46assert.strictEqual(path.posix.normalize('a/​/​b/​/​./​c'), 'a/​b/​c');47assert.strictEqual(path.posix.normalize('a/​/​b/​/​.'), 'a/​b');48assert.strictEqual(path.posix.normalize('/​a/​b/​c/​../​../​../​x/​y/​z'), '/​x/​y/​z');49assert.strictEqual(path.posix.normalize('/​/​/​../​/​./​foo/​./​/​bar'), '/​foo/​bar');50assert.strictEqual(path.posix.normalize('bar/​foo../​../​'), 'bar/​');51assert.strictEqual(path.posix.normalize('bar/​foo../​..'), 'bar');52assert.strictEqual(path.posix.normalize('bar/​foo../​../​baz'), 'bar/​baz');53assert.strictEqual(path.posix.normalize('bar/​foo../​'), 'bar/​foo../​');54assert.strictEqual(path.posix.normalize('bar/​foo..'), 'bar/​foo..');55assert.strictEqual(path.posix.normalize('../​foo../​../​../​bar'), '../​../​bar');56assert.strictEqual(path.posix.normalize('../​.../​../​./​.../​../​../​bar'),57 '../​../​bar');58assert.strictEqual(path.posix.normalize('../​../​../​foo/​../​../​../​bar'),59 '../​../​../​../​../​bar');60assert.strictEqual(path.posix.normalize('../​../​../​foo/​../​../​../​bar/​../​../​'),61 '../​../​../​../​../​../​');62assert.strictEqual(63 path.posix.normalize('../​foobar/​barfoo/​foo/​../​../​../​bar/​../​../​'),64 '../​../​'65);66assert.strictEqual(67 path.posix.normalize('../​.../​../​foobar/​../​../​../​bar/​../​../​baz'),68 '../​../​../​../​baz'69);...

Full Screen

Full Screen

shell.js

Source: shell.js Github

copy

Full Screen

...15 var nfdStr = stringify(test.NFD);16 var nfkcStr = stringify(test.NFKC);17 var nfkdStr = stringify(test.NFKD);18 /​* NFC */​19 assertEq(source.normalize(), NFC, "NFC of " + sourceStr);20 assertEq(NFC.normalize(), NFC, "NFC of " + nfcStr);21 assertEq(NFD.normalize(), NFC, "NFC of " + nfdStr);22 assertEq(NFKC.normalize(), NFKC, "NFC of " + nfkcStr);23 assertEq(NFKD.normalize(), NFKC, "NFC of " + nfkdStr);24 assertEq(source.normalize(undefined), NFC, "NFC of " + sourceStr);25 assertEq(NFC.normalize(undefined), NFC, "NFC of " + nfcStr);26 assertEq(NFD.normalize(undefined), NFC, "NFC of " + nfdStr);27 assertEq(NFKC.normalize(undefined), NFKC, "NFC of " + nfkcStr);28 assertEq(NFKD.normalize(undefined), NFKC, "NFC of " + nfkdStr);29 assertEq(source.normalize("NFC"), NFC, "NFC of " + sourceStr);30 assertEq(NFC.normalize("NFC"), NFC, "NFC of " + nfcStr);31 assertEq(NFD.normalize("NFC"), NFC, "NFC of " + nfdStr);32 assertEq(NFKC.normalize("NFC"), NFKC, "NFC of " + nfkcStr);33 assertEq(NFKD.normalize("NFC"), NFKC, "NFC of " + nfkdStr);34 /​* NFD */​35 assertEq(source.normalize("NFD"), NFD, "NFD of " + sourceStr);36 assertEq(NFC.normalize("NFD"), NFD, "NFD of " + nfcStr);37 assertEq(NFD.normalize("NFD"), NFD, "NFD of " + nfdStr);38 assertEq(NFKC.normalize("NFD"), NFKD, "NFD of " + nfkcStr);39 assertEq(NFKD.normalize("NFD"), NFKD, "NFD of " + nfkdStr);40 /​* NFKC */​41 assertEq(source.normalize("NFKC"), NFKC, "NFKC of " + sourceStr);42 assertEq(NFC.normalize("NFKC"), NFKC, "NFKC of " + nfcStr);43 assertEq(NFD.normalize("NFKC"), NFKC, "NFKC of " + nfdStr);44 assertEq(NFKC.normalize("NFKC"), NFKC, "NFKC of " + nfkcStr);45 assertEq(NFKD.normalize("NFKC"), NFKC, "NFKC of " + nfkdStr);46 /​* NFKD */​47 assertEq(source.normalize("NFKD"), NFKD, "NFKD of " + sourceStr);48 assertEq(NFC.normalize("NFKD"), NFKD, "NFKD of " + nfcStr);49 assertEq(NFD.normalize("NFKD"), NFKD, "NFKD of " + nfdStr);50 assertEq(NFKC.normalize("NFKD"), NFKD, "NFKD of " + nfkcStr);51 assertEq(NFKD.normalize("NFKD"), NFKD, "NFKD of " + nfkdStr);...

Full Screen

Full Screen

normalize.js

Source: normalize.js Github

copy

Full Screen

...3import {percentile, take} from "../​options.js";4import {mapX, mapY} from "./​map.js";5export function normalizeX(basis, options) {6 if (arguments.length === 1) ({basis, ...options} = basis);7 return mapX(normalize(basis), options);8}9export function normalizeY(basis, options) {10 if (arguments.length === 1) ({basis, ...options} = basis);11 return mapY(normalize(basis), options);12}13export function normalize(basis) {14 if (basis === undefined) return normalizeFirst;15 if (typeof basis === "function") return normalizeBasis((I, S) => basis(take(S, I)));16 if (/​^p\d{2}$/​i.test(basis)) return normalizeAccessor(percentile(basis));17 switch (`${basis}`.toLowerCase()) {18 case "deviation": return normalizeDeviation;19 case "first": return normalizeFirst;20 case "last": return normalizeLast;21 case "max": return normalizeMax;22 case "mean": return normalizeMean;23 case "median": return normalizeMedian;24 case "min": return normalizeMin;25 case "sum": return normalizeSum;26 case "extent": return normalizeExtent;27 }...

Full Screen

Full Screen

NormalizePolyfill.qunit.js

Source: NormalizePolyfill.qunit.js Github

copy

Full Screen

1/​*global String QUnit */​2sap.ui.define(["sap/​base/​strings/​NormalizePolyfill"], function(normalizePolyfill) {3 "use strict";4 QUnit.module("NormalizePolyfill", {5 beforeEach: function () {6 this.fnNormalize = String.prototype.normalize;7 }, afterEach: function () {8 /​* eslint-disable no-extend-native */​9 String.prototype.normalize = this.fnNormalize;10 /​* eslint-enable no-extend-native */​11 }12 });13 QUnit.test("apply polyfill", function(assert) {14 normalizePolyfill.apply();15 assert.ok(String.prototype.normalize);16 assert.ok(typeof String.prototype.normalize === 'function');17 });18 QUnit.test("apply polyfill and compare to prototype", function(assert) {19 normalizePolyfill.apply();20 assert.notStrictEqual(String.prototype.normalize, this.fnNormalize, "the newly set normalize function is not the same as the original");21 });...

Full Screen

Full Screen

StackOverFlow community discussions

Questions
Discussion

How to test parallel, mocked data requests in JEST whilst simulating cached responses with a 500ms threshold

Jest mock timers not working as expected asynchronously; how to make this test pass?

Travis/Jest: TypeError: Cannot assign to read only property &#39;Symbol(Symbol.toStringTag)&#39; of object &#39;#&lt;process&gt;&#39;

Migrating create-react-app from javascript to typescript

Test failing cases with React, Jest, React-Testing-Library

How do I test a jest console.log

Jest mock window object before importing a dependency

How to test methods inside functional component using enzyme as instance() returns null for shallow wrapper?

Using Jest property matchers on arrays of objects

What is the scope of mocks in jest?

It looks like your first tests don't work properly as well.

So for data loaded within 500ms the output should be "A1B1", else, after 500ms, it should be "A2B2" and so on.

But later you said

Tests for the data "A1B1", "B1C1" are fine, but because the latency (in the mockLoading function) is always above the 500ms threshold, I am not able to get the right results for data returned after that. In effect, "A2B2" and "B2C2" always fail.

Easiest way will be to pass time to requestAandB and requestBandC, because using Math.random() can give you random numbers and might fail tests randomly. So try this approach:

test('Test cache timings ', () =>
  Promise.all([
    // send two requests in parallel after 0 ms (immediately)
    expect(requestAandB(0)).resolves.toEqual('A1B1'),
    expect(requestBandC(0)).resolves.toEqual('B1C1'),

    // send two requests in parallel after 480 ms
    expect(requestAandB(480)).resolves.toEqual('A1B1'),
    expect(requestBandC(480)).resolves.toEqual('B1C1'),

    // send two requests in parallel after 520 ms
    expect(requestAandB(520)).resolves.toEqual('A2B2'),
    expect(requestBandC(520)).resolves.toEqual('B2C2'),

    // send two requests in parallel after 360 ms
    expect(requestAandB(360)).resolves.toEqual('A1B1'),
    expect(requestBandC(360)).resolves.toEqual('B1C1'),

    // send two requests in parallel after 750 ms
    expect(requestAandB(750)).resolves.toEqual('A2B2'),
    expect(requestBandC(750)).resolves.toEqual('B2C2'),
  ]));

index.js

const { loadDataA, loadDataB, loadDataC } = require('./get-data.js');

async function requestAandB(time) {
  const temp = await Promise.all([
    loadDataA(time),
    loadDataB(time),
    loadDataC(time),
  ]); // don't use global Promise outside of this function

  return temp.filter((_, i) => i < 2).join('');
}

async function requestBandC(time) {
  const temp = await Promise.all([
    loadDataA(time),
    loadDataB(time),
    loadDataC(time),
  ]); // don't use global Promise outside of this function

  return temp.filter((_, i) => i > 0).join('');
}

module.exports = { requestAandB, requestBandC };

get-data.js

// get-data.js
const { wait } = require('./wait.js');

async function mockLoading(time, str) {
  await wait(time);

  // here is the logic if time is less then 500ms then append 1 else append 2
  let label = str;
  if (Math.ceil(time / 500) <= 1) {
     label += '1';
  } else {
     label += '2';
  }

  return label;
}

module.exports = {
  loadDataA: async time => mockLoading(time, 'A'),
  loadDataB: async time => mockLoading(time, 'B'),
  loadDataC: async time => mockLoading(time, 'C'),
};
https://stackoverflow.com/questions/68030700/how-to-test-parallel-mocked-data-requests-in-jest-whilst-simulating-cached-resp

Blogs

Check out the latest blogs from LambdaTest on this topic:

19 Best Practices For Automation testing With Node.js

Node js has become one of the most popular frameworks in JavaScript today. Used by millions of developers, to develop thousands of project, node js is being extensively used. The more you develop, the better the testing you require to have a smooth, seamless application. This article shares the best practices for the testing node.in 2019, to deliver a robust web application or website.

Jest Testing Tutorial: A Complete Guide With Examples

This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Selenium JavaScript Tutorial.

A Comprehensive Guide To Storybook Testing

Storybook offers a clean-room setting for isolating component testing. No matter how complex a component is, stories make it simple to explore it in all of its permutations. Before we discuss the Storybook testing in any browser, let us try and understand the fundamentals related to the Storybook framework and how it simplifies how we build UI components.

How To Choose The Best JavaScript Unit Testing Frameworks

JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.

A Beginner’s Guide To Next.js Testing

There’s always an edge in learning new tools and technologies. As the market evolves, it’s constantly changing how we build our websites. One of the top benefits of why you should learn Next.js is how proficient we become when it comes to website development. This creates a perfect opportunity for companies that decide to trust the actual capabilities and functionalities offered by modern technologies such as Next.js.

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