Skip to content

Commit

Permalink
fix for addReplaceTerm
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhaim1 committed Feb 19, 2024
1 parent b19c175 commit 3579fbd
Show file tree
Hide file tree
Showing 4 changed files with 821 additions and 721 deletions.
42 changes: 41 additions & 1 deletion __tests__/TitleCaser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ describe(`
"announcing a new collaboration with the cybersmile foundation: how to combat cyberbullying",
"Announcing a New Collaboration With The Cybersmile Foundation: How to Combat Cyberbullying"
);

});

describe(`
Expand Down Expand Up @@ -454,3 +453,44 @@ describe(`
.toEqual(expectedOutput);
});
});

describe('Test addReplaceTerm Method', () => {
let titleCaser;

// Setup a new TitleCaser instance before each test
beforeEach(() => {
titleCaser = new TitleCaser({ style: 'ap' });
});

test('adds a new replacement term correctly', () => {
const term = 'js';
const replacement = 'JavaScript';

// Initially, ensure the term does not exist in the replacement list
expect(titleCaser.wordReplacementsList.some((obj) => obj.hasOwnProperty(term))).toBeFalsy();

// Add the new replacement term
titleCaser.addReplaceTerm(term, replacement);

// Verify the term now exists in the replacement list with the correct replacement value
expect(titleCaser.wordReplacementsList.some((obj) => obj[term] === replacement)).toBeTruthy();
});

test('updates an existing replacement term correctly', () => {
const initialTerm = 'js';
const initialReplacement = 'JavaScript';
const newReplacement = 'JS';

// Add an initial replacement term
titleCaser.addReplaceTerm(initialTerm, initialReplacement);

// Verify the term exists with the initial replacement value
expect(titleCaser.wordReplacementsList.some((obj) => obj[initialTerm] === initialReplacement)).toBeTruthy();

// Update the replacement term
titleCaser.addReplaceTerm(initialTerm, newReplacement);

// Verify the term now exists with the new replacement value
expect(titleCaser.wordReplacementsList.some((obj) => obj[initialTerm] === newReplacement)).toBeTruthy();
});
});
Loading

0 comments on commit 3579fbd

Please sign in to comment.