diff --git a/package-lock.json b/package-lock.json index b7a5837..a43123b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "codi-test-framework", - "version": "0.0.31", + "version": "0.0.32", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "codi-test-framework", - "version": "0.0.31", + "version": "0.0.32", "license": "MIT", "dependencies": { "chalk": "^5.3.0", diff --git a/src/assertions/assertNoDuplicates.js b/src/assertions/assertNoDuplicates.js index 0bbda08..18536aa 100644 --- a/src/assertions/assertNoDuplicates.js +++ b/src/assertions/assertNoDuplicates.js @@ -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)}`); } } \ No newline at end of file diff --git a/tests/example.test.mjs b/tests/example.test.mjs index ac107d6..d4fea05 100644 --- a/tests/example.test.mjs +++ b/tests/example.test.mjs @@ -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'; @@ -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', () => { @@ -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'); + }); + }); \ No newline at end of file