From 47ce7cf0680184f4dd1d9daf66415bcefe79bed0 Mon Sep 17 00:00:00 2001 From: Corbin Crutchley Date: Mon, 25 Oct 2021 13:34:37 -0700 Subject: [PATCH] Added upstream matches tests --- src/__tests__/matches.js | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/__tests__/matches.js diff --git a/src/__tests__/matches.js b/src/__tests__/matches.js new file mode 100644 index 0000000..3d512e6 --- /dev/null +++ b/src/__tests__/matches.js @@ -0,0 +1,41 @@ +import {fuzzyMatches, matches} from '../matches' + +// unit tests for text match utils + +const node = null +const normalizer = str => str + +test('matchers accept strings', () => { + expect(matches('ABC', node, 'ABC', normalizer)).toBe(true) + expect(fuzzyMatches('ABC', node, 'ABC', normalizer)).toBe(true) +}) + +test('matchers accept regex', () => { + expect(matches('ABC', node, /ABC/, normalizer)).toBe(true) + expect(fuzzyMatches('ABC', node, /ABC/, normalizer)).toBe(true) +}) + +test('matchers accept functions', () => { + expect(matches('ABC', node, text => text === 'ABC', normalizer)).toBe(true) + expect(fuzzyMatches('ABC', node, text => text === 'ABC', normalizer)).toBe( + true, + ) +}) + +test('matchers return false if text to match is not a string', () => { + expect(matches(null, node, 'ABC', normalizer)).toBe(false) + expect(fuzzyMatches(null, node, 'ABC', normalizer)).toBe(false) +}) + +test('matchers throw on invalid matcher inputs', () => { + expect(() => + matches('ABC', node, null, normalizer), + ).toThrowErrorMatchingInlineSnapshot( + `It looks like null was passed instead of a matcher. Did you do something like getByText(null)?`, + ) + expect(() => + fuzzyMatches('ABC', node, undefined, normalizer), + ).toThrowErrorMatchingInlineSnapshot( + `It looks like undefined was passed instead of a matcher. Did you do something like getByText(undefined)?`, + ) +}) -- knotmirror 0.0.1