How to use compareSpecificities method in unexpected

Best JavaScript code snippet using unexpected

cssproperties.js

Source:cssproperties.js Github

copy

Full Screen

...683 case ".": refSpecificity = {a:0, b:0, c:1, d:0}; break;684 case "": refSpecificity = {a:0, b:0, c:0, d:1}; break;685 default: break; // should never happen686 }687 if (compareSpecificities(refSpecificity, spec) >= 0) { 688 var existingRule = CssInspector.findLastRuleInRulesetForSelector(ruleset, aDelimitor + aIdent);689 if (existingRule &&690 (!existingRule.parentStyleSheet.href || existingRule.parentStyleSheet.href.substr(0, 4) != "http")) {691 rv.sheet = existingRule.parentStyleSheet;692 rv.rule = inspectedRule.rule;693 rv.priority = priority;694 return rv;695 }696 // cool, we can just create a new rule with an ID selector697 // but don't forget to set the priority...698 rv.sheet = sheet;699 rv.priority = priority;700 return rv;701 }702 // at this point, we have a greater specificity; hum, then what's703 // the priority of the declaration?704 if (!priority) {705 var existingRule = CssInspector.findLastRuleInRulesetForSelector(ruleset, aDelimitor + aIdent);706 if (existingRule &&707 (!existingRule.parentStyleSheet.href || existingRule.parentStyleSheet.href.substr(0, 4) != "http")) {708 rv.sheet = existingRule.parentStyleSheet;709 rv.rule = inspectedRule.rule;710 rv.priority = "important";711 return rv;712 }713 // no priority, so cool we can create a !important declaration714 // for the ID715 rv.sheet = sheet;716 rv.priority = "important";717 return rv;718 }719 // argl, it's already a !important declaration :-( our only720 // choice is a !important style attribute... We can't just clean the721 // style on inspectedRule because some other rules could also apply722 // is that one goes away.723 // nothing to set724 return rv;725 }726 // oh, the property is not applied yet, let's just create a rule727 // with the ID selector for that property728 var sheet;729 var existingRule = CssInspector.findLastRuleInRulesetForSelector(ruleset, aDelimitor + aIdent);730 if (existingRule &&731 (!existingRule.parentStyleSheet.href || existingRule.parentStyleSheet.href.substr(0, 4) != "http")) {732 rv.sheet = existingRule.parentStyleSheet;733 rv.rule = existingRule;734 }735 else {736 rv.sheet = FindLastEditableStyleSheet();737 }738 return rv;739}740function ToggleHover(aElt)741{742 if (aElt.checked && gDialog.cssPolicyMenulist.value == "inline")743 gDialog.cssPolicyMenulist.value = "id";744 var node = gCurrentElement;745 SelectionChanged(null, node, null);746}747function RulesMatchesQuery(rule, query)748{749 if (!query) // no media query specified, we always match750 return true;751 //query = "screen and (max-width: " + query + "px)";752 if ((rule.parentRule &&753 rule.parentRule.type == CSSRule.MEDIA_RULE &&754 rule.parentRule.media.mediaText == query) ||755 (rule.parentStyleSheet &&756 rule.parentStyleSheet.media &&757 rule.parentStyleSheet.media.mediaText == query))758 return true;759 760 return false;761}762function compareSpecificities(s1, s2)763{764 if (s1.a > s2.a ||765 (s1.a == s2.a && s1.b > s2.b) ||766 (s1.a == s2.a && s1.b == s2.b && s1.c > s2.c) ||767 (s1.a == s2.a && s1.b == s2.b && s1.c == s2.c && s1.d > s2.d))768 return +1;769 if (s2.a > s1.a ||770 (s2.a == s1.a && s2.b > s1.b) ||771 (s2.a == s1.a && s2.b == s1.b && s2.c > s1.c) ||772 (s2.a == s1.a && s2.b == s1.b && s2.c == s1.c && s2.d > s1.d))773 return -1;774 return 0;775}776function FindWhereToInsertRuleForPrint(ruleset, property, value, aDelimitor, aRegExpDelimitor, aIdent, aElement)777{778 var rv = { sheet: null,779 rule: null,780 priority: "",781 impossible: false };782 var inspectedRule = CssInspector.findRuleForProperty(ruleset, property);783 if (inspectedRule && inspectedRule.rule && RulesMatchesQuery(inspectedRule.rule, "print")) {784 // ok, that property is already applied through a CSS rule785 // is that rule dependent on the ID selector for that ID?786 // if yes, let's try to tweak it787 var priority = inspectedRule.rule.style.getPropertyPriority(property);788 var selector = inspectedRule.rule.selectorText;789 var r = new RegExp( aRegExpDelimitor + aIdent + "$|" + aRegExpDelimitor + aIdent + "[\.:,\\[]", "g");790 if (selector.match(r)) {791 // yes! can we edit the corresponding stylesheet or not?792 var sheet = inspectedRule.rule.parentStyleSheet;793 var topSheet = sheet;794 while (topSheet.parentStyleSheet)795 topSheet = topSheet.parentStyleSheet;796 if (topSheet.ownerNode &&797 (!sheet.href || sheet.href.substr(0, 4) != "http")) {798 // yes we can edit it...799 rv.sheet = sheet;800 rv.rule = inspectedRule.rule;801 rv.priority = priority;802 return rv;803 }804 }805 }806 var sheet = FindLastEditableStylesheetForPrint();807 rv.sheet = sheet;808 function findMediaPrintRuleOrMatch(aRules, aElement, aDelimitor, aSelectorText, aTop) {809 var refSpecificity = {a:0, b:0, c:0, d:0};810 switch (aDelimitor) {811 case "#": refSpecificity = {a:0, b:1, c:0, d:0}; break;812 case ".": refSpecificity = {a:0, b:0, c:1, d:0}; break;813 case "": refSpecificity = {a:0, b:0, c:0, d:1}; break;814 default: break; // should never happen815 }816 if (aRules.length) {817 var index = aRules.length - 1;818 while (index >= 0) {819 var rule = aRules.item(index);820 if (rule.type == CSSRule.STYLE_RULE) {821 if (!aTop && rule.selectorText == aSelectorText)822 return rule;823 if (aElement.mozMatchesSelector(rule.selectorText)) {824 var parser = new CSSParser();825 parser._init();826 parser.mPreserveWS = false;827 parser.mPreserveComments = false;828 parser.mPreservedTokens = [];829 parser.mScanner.init(rule.selectorText);830 var token = parser.getToken(false, false);831 if (token.isNotNull()) {832 var selector = parser.parseSelector(token, true);833 if (compareSpecificities(selector.specificity, refSpecificity) >= 0)834 return aTop ? null : rule.parentRule; // gah we need to create a new rule835 }836 }837 }838 else if (rule.type == CSSRule.MEDIA_RULE && rule.media.mediaText == "print") {839 var r = findMediaPrintRuleOrMatch(rule.cssRules, aElement, aDelimitor, aSelectorText, false);840 return r ? r : rule;841 }842 index--;843 }844 }845 return null;846 }847 rv.rule = findMediaPrintRuleOrMatch(sheet.cssRules, aElement, aDelimitor, aDelimitor + aIdent, true);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1expect.spyOn(sinon, 'expectation').andCallThrough();2expect.spyOn(sinon, 'spy').andCallThrough();3expect.spyOn(sinon, 'stub').andCallThrough();4expect.spyOn(sinon, 'mock').andCallThrough();5expect.spyOn(sinon, 'expectation').andCallThrough();6expect.spyOn(sinon, 'spy').andCallThrough();7expect.spyOn(sinon, 'stub').andCallThrough();8expect.spyOn(sinon, 'mock').andCallThrough();9expect.spyOn(sinon, 'expectation').andCallThrough();10expect.spyOn(sinon, 'spy').andCallThrough();11expect.spyOn(sinon, 'stub').andCallThrough();12expect.spyOn(sinon, 'mock').andCallThrough();13expect.spyOn(sinon, 'expectation').andCallThrough();14expect.spyOn(sinon, 'spy').andCallThrough();15expect.spyOn(sinon, 'stub').andCallThrough();16expect.spyOn(sinon, 'mock').andCallThrough();17expect.spyOn(sinon, 'expectation').andCallThrough();18expect.spyOn(sinon, 'spy').andCallThrough();19expect.spyOn(sinon, 'stub').andCallThrough();20expect.spyOn(sinon, 'mock').andCallThrough();21expect.spyOn(sinon, 'expectation').andCallThrough();22expect.spyOn(sinon, 'spy').andCallThrough();23expect.spyOn(sinon, 'stub').andCallThrough();24expect.spyOn(sinon, 'mock').andCallThrough();25expect.spyOn(sinon, 'expectation').andCallThrough();26expect.spyOn(sinon, 'spy').andCallThrough();27expect.spyOn(sinon, 'stub').andCallThrough();28expect.spyOn(sinon, 'mock').andCallThrough();

Full Screen

Using AI Code Generation

copy

Full Screen

1const expect = require('unexpected-sinon');2const sinon = require('sinon');3const mySpy = sinon.spy();4mySpy(1, 2, 3);5expect(mySpy, 'was called with', 1, 2, 3);6const expect = require('unexpected');7const sinon = require('sinon');8const mySpy = sinon.spy();9mySpy(1, 2, 3);10expect(mySpy, 'was called with', 1, 2, 3);11const expect = require('unexpected-sinon');12const sinon = require('sinon');13const mySpy = sinon.spy();14mySpy(1, 2, 3);15expect(mySpy, 'was called with', 1, 2, 3);16const expect = require('unexpected');17const sinon = require('sinon');18const mySpy = sinon.spy();19mySpy(1, 2, 3);20expect(mySpy, 'was called with', 1, 2, 3);21const expect = require('unexpected-sinon');22const sinon = require('sinon');23const mySpy = sinon.spy();24mySpy(1, 2, 3);25expect(mySpy, 'was called with', 1, 2, 3);26const expect = require('unexpected');27const sinon = require('sinon');28const mySpy = sinon.spy();29mySpy(1, 2, 3);30expect(mySpy, 'was called with', 1, 2, 3);31const expect = require('unexpected-sinon');32const sinon = require('sinon');33const mySpy = sinon.spy();34mySpy(1, 2, 3);35expect(mySpy, 'was called with', 1, 2, 3);36const expect = require('unexpected');37const sinon = require('sinon');38const mySpy = sinon.spy();

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var expect = require('unexpected-sinon');3describe('my test', function () {4 it('should work', function () {5 var spy = sinon.spy();6 spy(1, 2);7 expect(spy, 'was called with', 1, 2);8 });9});10### expect(actual, [assertionName], [...args])11### expect.addAssertion([name], [flags], handler)12expect.addAssertion('<spy> to have been called with', function (expect, subject, args) {13 expect(subject, 'was called');14 expect(subject.args, 'to satisfy', [[].slice.call(args)]);15});16### expect.addType(options)17- `identify` - a function that takes a value and returns `true` if it is of this type, e.g. `function (value) { return value instanceof sinon.spy; }`18- `equal` - a function that takes two values of this type and returns `true` if they are equal, e.g. `function (a, b) { return a === b; }`19- `inspect` - a function that takes a value of this type and returns a string representation of it, e.g. `function (value, depth, output) { return output.text(value.toString()); }`20### expect.output.text(str)

Full Screen

Using AI Code Generation

copy

Full Screen

1const expect = require('unexpected').clone().use(require('unexpected-sinon'));2const sinon = require('sinon');3const path = require('path');4const compareSpecificities = require('unexpected-sinon/lib/compareSpecificities');5const sinonSpy = sinon.spy();6const sinonStub = sinon.stub();7const sinonMock = sinon.mock();8const sinonFake = sinon.fake();9const sinonFakeTimers = sinon.useFakeTimers();10const sinonFakeServer = sinon.fakeServer.create();11const sinonFakeServerWithClock = sinon.useFakeXMLHttpRequest();12const sinonFakeServerWithClockAndTimers = sinon.useFakeTimers({ now: 0 });13const sinonFakeServerWithClockAndTimersAndRequest = sinon.useFakeXMLHttpRequest();14const sinonFakeServerWithClockAndTimersAndRequestAndServer = sinon.fakeServer.create();15const sinonFakeServerWithClockAndTimersAndRequestAndServerAndStub = sinon.stub();16const sinonFakeServerWithClockAndTimersAndRequestAndServerAndStubAndMock = sinon.mock();17expect(18);19expect(

Full Screen

Using AI Code Generation

copy

Full Screen

1const sinon = require('sinon');2const expect = require('unexpected-sinon');3const test = require('tape');4test('test', (t) => {5 t.plan(1);6 const spy = sinon.spy();7 spy('foo', 'bar');8 expect(spy, 'was called with', 'foo', 'bar');9 t.pass('test passed');10});11unexpected-sinon is a wrapper around [unexpected-sinon](

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var expect = require('unexpected-sinon');3var myObj = {4 myMethod: function () {5 console.log('hello world');6 }7};8expect(myObj, 'to have a property', 'm

Full Screen

Using AI Code Generation

copy

Full Screen

1var expect = require('unexpected')2 .clone()3 .use(require('unexpected-dom'));4var selector1 = '#id1';5var selector2 = '.class1';6var result = expect.compareSpecificities(selector1, selector2);7console.log(result);8selector1 = '.class1.class2';9selector2 = '.class1';10result = expect.compareSpecificities(selector1, selector2);11console.log(result);12selector1 = '.class1.class2';13selector2 = '.class1.class2';14result = expect.compareSpecificities(selector1, selector2);15console.log(result);16selector1 = '.class1.class2';17selector2 = '.class1.class3';18result = expect.compareSpecificities(selector1, selector2);19console.log(result);20selector1 = '.class1.class2';21selector2 = '.class1.class2.class3';22result = expect.compareSpecificities(selector1, selector2);23console.log(result);24selector1 = '.class1.class2';25selector2 = '.class1.class2.class3';26result = expect.compareSpecificities(selector1, selector2);27console.log(result);28selector1 = '#id1.class1.class2';29selector2 = '.class1.class2';30result = expect.compareSpecificities(selector1, selector2);31console.log(result);32selector1 = '#id1.class1.class2';33selector2 = '#id1.class1.class2.class3';34result = expect.compareSpecificities(selector1, selector2);35console.log(result);36selector1 = 'div.class1.class2';37selector2 = '#id1.class1.class2.class3';38result = expect.compareSpecificities(selector1, selector2);39console.log(result);40selector1 = 'div.class1.class2';41selector2 = '#id1.class1.class2.class3';42result = expect.compareSpecificities(selector1, selector2);43console.log(result);44selector1 = 'div.class1.class2';45selector2 = '#id1.class1.class2.class3';46result = expect.compareSpecificities(selector1, selector2);47console.log(result);48selector1 = 'div.class1.class2';

Full Screen

Using AI Code Generation

copy

Full Screen

1const expect = require('unexpected-sinon');2const compareSpecificities = expect.compareSpecificities;3const selector1 = '.foo .bar .baz';4const selector2 = '.foo .bar';5const result = compareSpecificities(selector1, selector2);6#### compareSpecificities(selector1, selector2)

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run unexpected 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