Skip to content

Commit

Permalink
Update duplicates check
Browse files Browse the repository at this point in the history
  • Loading branch information
RobAndrewHurst committed Sep 12, 2024
1 parent bdb7545 commit 47be8f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/assertions/assertNoDuplicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import chalk from "chalk";

export function assertNoDuplicates(arr, message) {
//Filter array until for duplicate entries
arr => arr.filter((item, index) => arr.indexOf(item) !== index)
if (arr > 0) {
arr = arr.filter((item, index) => arr.indexOf(item) !== index)
if (arr.length > 0) {
throw new Error(message || `Duplicates found: ${chalk.bold.yellow(arr)}`);
}
}
9 changes: 7 additions & 2 deletions tests/example.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, assertEqual, assertNotEqual, assertTrue, assertFalse, assertThrows } from '../src/testRunner.js';
import { describe, it, assertEqual, assertNotEqual, assertTrue, assertFalse, assertThrows, assertNoDuplicates } from '../src/testRunner.js';

import { helloworld } from '../example/example.mjs';

Expand All @@ -15,7 +15,7 @@ describe('I am an Example Test Suite', () => {
});

it('should pass inequality assertion', () => {
assertNotEqual(1, 2, 'Expected 1 not to equal 2');
assertNotEqual(1, 2, 'Expected 1 not to equal 2');
});

it('should pass true assertion', () => {
Expand All @@ -38,4 +38,9 @@ describe('I am an Example Test Suite', () => {
assertEqual(obj1, obj2, 'Expected objects to be deeply equal');
});

it('should check for duplicates', () => {
const array = ['field1', 'field2']
assertNoDuplicates(array, 'There should be no duplicates');
});

});

0 comments on commit 47be8f6

Please sign in to comment.