tests(Type Guards): Refactor test loops for better readability
@@ -33,9 +33,8 @@ describe('nodeIs', () => {
// @ts-ignore
expect(nodeIs(typeMap)(undefined)).toBe(false))
- test('returns false for primitive values', () => {
- primitives.map(node => expect(nodeIs(typeMap)(node)).toBe(false))
- expect.assertions(primitives.length)
+ test.each(primitives)('returns false for primitive value of "%s"', node => {
+ expect(nodeIs(typeMap)(node)).toBe(false)
})
test('it returns false for empty Arrays', () =>
@@ -100,9 +99,8 @@ describe('isType', () => {
})
describe('isPrimitive', () => {
- test('returns true for primitive values', () => {
- primitives.map(node => expect(isPrimitive(node)).toBe(true))
- expect.assertions(primitives.length)
+ test.each(primitives)('returns true for primitive value of "%s"', node => {
+ expect(isPrimitive(node)).toBe(true)
})
test('it returns false for empty Arrays', () =>
@@ -116,9 +114,8 @@ describe('isPrimitive', () => {
})
describe('isInlineEntity', () => {
- test('returns false for primitive values', () => {
- primitives.map(node => expect(isInlineEntity(node)).toBe(false))
- expect.assertions(primitives.length)
+ test.each(primitives)('returns false for primitive value of "%s"', node => {
+ expect(isInlineEntity(node)).toBe(false)
})
test('it returns false for empty Arrays', () =>
@@ -138,23 +135,22 @@ describe('isInlineEntity', () => {
})
describe('isInlineContent', () => {
- test('returns true for primitive types', () => {
- primitives.map(type => expect(isInlineContent(type)).toBe(true))
+ test.each(primitives)('returns true for primitive value of "%s"', type => {
+ expect(isInlineContent(type)).toBe(true)
})
- test('returns false for BlockContent types ', () => {
- Object.values(blockContentTypes).map(type => {
+ test.each(Object.values(blockContentTypes))(
+ 'returns false for BlockContent type of "%s"',
+ type => {
expect(isInlineContent({ type })).toBe(false)
- })
-
- expect.assertions(Object.values(blockContentTypes).length)
- })
+ }
+ )
- test('returns true for InlineContent types ', () => {
- Object.values(inlineContentTypes).map(type => {
+ test.each(Object.values(inlineContentTypes))(
+ 'returns true for InlineContent type of "%s"',
+ type => {
expect(isInlineContent({ type })).toBe(true)
+ }
+ )
})
- expect.assertions(Object.values(inlineContentTypes).length)
- })
-})
