n8n/packages/nodes-base/test/utils/utilities.test.ts
2023-02-21 15:42:00 +02:00

32 lines
940 B
TypeScript

import { fuzzyCompare } from '../../utils/utilities';
//most test cases for fuzzyCompare are done in Compare Datasets node tests
describe('Test fuzzyCompare', () => {
it('should do strict comparison', () => {
const compareFunction = fuzzyCompare(false);
expect(compareFunction(1, '1')).toEqual(false);
});
it('should do fuzzy comparison', () => {
const compareFunction = fuzzyCompare(true);
expect(compareFunction(1, '1')).toEqual(true);
});
it('should treat null, 0 and "0" as equal', () => {
const compareFunction = fuzzyCompare(true, 2);
expect(compareFunction(null, null)).toEqual(true);
expect(compareFunction(null, 0)).toEqual(true);
expect(compareFunction(null, '0')).toEqual(true);
});
it('should not treat null, 0 and "0" as equal', () => {
const compareFunction = fuzzyCompare(true);
expect(compareFunction(null, 0)).toEqual(false);
expect(compareFunction(null, '0')).toEqual(false);
});
});