Skip to content

Commit

Permalink
Merge pull request #21325 from Yoast/td/class-syntax
Browse files Browse the repository at this point in the history
Transforms prototype-based classes to regular class syntax
  • Loading branch information
FAMarfuaty committed Sep 18, 2024
2 parents abc2cb2 + f8bdf14 commit 1302935
Show file tree
Hide file tree
Showing 51 changed files with 3,711 additions and 4,399 deletions.
24 changes: 19 additions & 5 deletions packages/yoastseo/spec/appSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import MissingArgument from "../src/errors/missingArgument.js";
import App from "../src/app.js";
import Factory from "../src/helpers/factory";

// Mock these function to prevent us from needing an actual DOM in the tests.
App.prototype.showLoadingDialog = function() {};
Expand All @@ -8,23 +9,23 @@ App.prototype.removeLoadingDialog = function() {};
App.prototype.runAnalyzer = function() {};

// Makes lodash think this is a valid HTML element
var mockElement = [];
const mockElement = [];
mockElement.nodeType = 1;

global.document = {};
document.getElementById = function() {
return mockElement;
};

const researcher = Factory.buildMockResearcher( {}, true, false );

describe( "Creating an App", function() {
it( "throws an error when no args are given", function() {
expect( App ).toThrowError( MissingArgument );
expect( () => new App() ).toThrowError( MissingArgument );
} );

it( "throws on an empty args object", function() {
expect( function() {
new App( {} );
} ).toThrowError( MissingArgument );
expect( () => new App( {} ) ).toThrowError( MissingArgument );
} );

it( "throws on an invalid targets argument", function() {
Expand All @@ -50,6 +51,17 @@ describe( "Creating an App", function() {
} ).toThrowError( MissingArgument );
} );

it( "throws on a missing researcher argument", function() {
expect( function() {
new App( {
targets: {
snippet: "snippetID",
output: "outputID",
},
} );
} ).toThrowError( MissingArgument );
} );

it( "should work without an output ID", function() {
new App( {
targets: {
Expand All @@ -60,6 +72,7 @@ describe( "Creating an App", function() {
return {};
},
},
researcher: researcher,
} );
} );

Expand All @@ -74,6 +87,7 @@ describe( "Creating an App", function() {
return {};
},
},
researcher: researcher,
} );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,5 @@ describe( "a test for serializing and parsing a Clause class instance", function
isPassive: false,
participles: [],
} );
expect( mockClause.parse( mockClause.serialize() ) ).toEqual( {
_clauseText: "The cat is loved.",
_auxiliaries: [ "is" ],
_isPassive: false,
_participles: [],
} );
} );
} );
10 changes: 0 additions & 10 deletions packages/yoastseo/spec/languageProcessing/values/SentenceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,5 @@ describe( "Creates a sentence object", function() {
isPassive: true,
sentenceText: "Cats are adored.",
} );
expect( sentence.parse( sentence.serialize() ) ).toEqual( {
_clauses: [
{ _auxiliaries: [ "are" ],
_clauseText: "Cats are adored",
_isPassive: true,
_participles: [],
} ],
_isPassive: true,
_sentenceText: "Cats are adored.",
} );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SubheadingDistributionTooLong from "../../../../src/scoring/assessments/r
import Paper from "../../../../src/values/Paper.js";
import Factory from "../../../../src/helpers/factory.js";
import Mark from "../../../../src/values/Mark.js";
import CornerStoneContentAssessor from "../../../../src/scoring/assessors/cornerstone/contentAssessor.js";
import CornerstoneContentAssessor from "../../../../src/scoring/assessors/cornerstone/contentAssessor.js";
import ProductCornerstoneContentAssessor from "../../../../src/scoring/assessors/productPages/cornerstone/contentAssessor.js";
import DefaultResearcher from "../../../../src/languageProcessing/languages/_default/Researcher.js";
import EnglishResearcher from "../../../../src/languageProcessing/languages/en/Researcher.js";
Expand Down Expand Up @@ -583,7 +583,7 @@ describe( "Language-specific configuration for specific types of content is used
expect( assessment._config.farTooMany ).toEqual( japaneseConfig.defaultParameters.farTooMany );
} );

let cornerStoneContentAssessor = new CornerStoneContentAssessor( englishResearcher );
let cornerStoneContentAssessor = new CornerstoneContentAssessor( englishResearcher );
let productCornerstoneContentAssessor = new ProductCornerstoneContentAssessor( englishResearcher, mockOptions );

[ cornerStoneContentAssessor, productCornerstoneContentAssessor ].forEach( assessor => {
Expand Down Expand Up @@ -617,7 +617,7 @@ describe( "Language-specific configuration for specific types of content is used
} );
} );

cornerStoneContentAssessor = new CornerStoneContentAssessor( japaneseResearcher );
cornerStoneContentAssessor = new CornerstoneContentAssessor( japaneseResearcher );
productCornerstoneContentAssessor = new ProductCornerstoneContentAssessor( japaneseResearcher, mockOptions );

[ cornerStoneContentAssessor, productCornerstoneContentAssessor ].forEach( assessor => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ describe( "A test for content assessor for English", function() {
expect( assessments.length ).toBe( expected );
expect( assessments.map( ( { identifier } ) => identifier ) ).toEqual(
[
"subheadingsTooLong",
"textParagraphTooLong",
"textSentenceLength",
"textTransitionWords",
"passiveVoice",
"textPresence",
"sentenceBeginnings",
"subheadingsTooLong",
"textSentenceLength",
"wordComplexity",
]
);
Expand Down Expand Up @@ -323,10 +323,10 @@ describe( "calculateOverallScore for non-English that uses Default researcher",
expect( assessments.length ).toBe( expected );
expect( assessments.map( ( { identifier } ) => identifier ) ).toEqual(
[
"subheadingsTooLong",
"textParagraphTooLong",
"textSentenceLength",
"textPresence",
"subheadingsTooLong",
"textSentenceLength",
]
);
} );
Expand Down
Loading

0 comments on commit 1302935

Please sign in to comment.