Skip to content

Commit

Permalink
test: tidy test syntax (#201)
Browse files Browse the repository at this point in the history
* test: use `toBe()` when expecting primitive literals

* test: replace `toThrowError()` with its canonical name `toThrow()`

* test: use `toBeNull()` instead of `toEqual(null)`
  • Loading branch information
Fdawgs committed Nov 29, 2022
1 parent 42d6481 commit ac0085d
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 82 deletions.
12 changes: 6 additions & 6 deletions src/ArraySchema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('ArraySchema', () => {
})
})
it('invalid', () => {
expect(() => ArraySchema().items('')).toThrowError(
expect(() => ArraySchema().items('')).toThrow(
new S.FluentSchemaError("'items' must be a S or an array of S")
)
})
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('ArraySchema', () => {
})
})
it('invalid', () => {
expect(() => ArraySchema().additionalItems('')).toThrowError(
expect(() => ArraySchema().additionalItems('')).toThrow(
new S.FluentSchemaError("'additionalItems' must be a boolean or a S")
)
})
Expand All @@ -102,7 +102,7 @@ describe('ArraySchema', () => {
ArraySchema()
.contains('')
.valueOf()
).toThrowError(new S.FluentSchemaError("'contains' must be a S"))
).toThrow(new S.FluentSchemaError("'contains' must be a S"))
})
})

Expand All @@ -122,7 +122,7 @@ describe('ArraySchema', () => {
ArraySchema()
.uniqueItems('invalid')
.valueOf()
).toThrowError(
).toThrow(
new S.FluentSchemaError("'uniqueItems' must be a boolean")
)
})
Expand All @@ -144,7 +144,7 @@ describe('ArraySchema', () => {
ArraySchema()
.minItems('3')
.valueOf()
).toThrowError(new S.FluentSchemaError("'minItems' must be a integer"))
).toThrow(new S.FluentSchemaError("'minItems' must be a integer"))
})
})

Expand All @@ -164,7 +164,7 @@ describe('ArraySchema', () => {
ArraySchema()
.maxItems('5')
.valueOf()
).toThrowError(new S.FluentSchemaError("'maxItems' must be a integer"))
).toThrow(new S.FluentSchemaError("'maxItems' must be a integer"))
})
})

Expand Down
56 changes: 28 additions & 28 deletions src/BaseSchema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('BaseSchema', () => {
it('invalid', () => {
expect(() => {
BaseSchema().id('')
}).toThrowError(
}).toThrow(
new S.FluentSchemaError(
'id should not be an empty fragment <#> or an empty string <> (e.g. #myId)'
)
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('BaseSchema', () => {
BaseSchema()
.examples(value)
.valueOf().examples
).toThrowError(
).toThrow(
new S.FluentSchemaError(
"'examples' must be an array e.g. ['1', 'one', 'foo']"
)
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('BaseSchema', () => {
expect(() => {
return S.object()
.prop('A', S.string()).required().required()
}).toThrowError(
}).toThrow(
new S.FluentSchemaError(
"'required' has repeated keys, check your calls to .required()"
)
Expand All @@ -170,7 +170,7 @@ describe('BaseSchema', () => {
return S.object()
.prop('A', S.string().required())
.prop('A', S.string().required())
}).toThrowError(
}).toThrow(
new S.FluentSchemaError(
"'required' has repeated keys, check your calls to .required()"
)
Expand All @@ -181,7 +181,7 @@ describe('BaseSchema', () => {
it('root-level required', () => {
expect(() => {
return S.object().required().valueOf()
}).toThrowError(
}).toThrow(
new S.FluentSchemaError(
"'required' has called on root-level schema, check your calls to .required()"
)
Expand Down Expand Up @@ -218,15 +218,15 @@ describe('BaseSchema', () => {
BaseSchema()
.deprecated(true)
.valueOf().deprecated
).toEqual(true)
).toBe(true)
})
it('invalid', () => {
expect(
() =>
BaseSchema()
.deprecated('somethingNotBoolean')
.valueOf().deprecated
).toThrowError(
).toThrow(
new S.FluentSchemaError(
"'deprecated' must be a boolean value"
)
Expand All @@ -237,14 +237,14 @@ describe('BaseSchema', () => {
BaseSchema()
.deprecated()
.valueOf().deprecated
).toEqual(true)
).toBe(true)
})
it('can be set to false', () => {
expect(
BaseSchema()
.deprecated(false)
.valueOf().deprecated
).toEqual(false)
).toBe(false)
})
it('property', () => {
expect(
Expand Down Expand Up @@ -394,7 +394,7 @@ describe('BaseSchema', () => {
BaseSchema()
.enum(value)
.valueOf().examples
).toThrowError(
).toThrow(
new S.FluentSchemaError(
"'enums' must be an array with at least an element e.g. ['1', 'one', 'foo']"
)
Expand Down Expand Up @@ -430,21 +430,21 @@ describe('BaseSchema', () => {
BaseSchema()
.readOnly(true)
.valueOf().readOnly
).toEqual(true)
).toBe(true)
})
it('valid with no value', () => {
expect(
BaseSchema()
.readOnly()
.valueOf().readOnly
).toEqual(true)
).toBe(true)
})
it('can be set to false', () => {
expect(
BaseSchema()
.readOnly(false)
.valueOf().readOnly
).toEqual(false)
).toBe(false)
})
})

Expand All @@ -454,21 +454,21 @@ describe('BaseSchema', () => {
BaseSchema()
.writeOnly(true)
.valueOf().writeOnly
).toEqual(true)
).toBe(true)
})
it('valid with no value', () => {
expect(
BaseSchema()
.writeOnly()
.valueOf().writeOnly
).toEqual(true)
).toBe(true)
})
it('can be set to false', () => {
expect(
BaseSchema()
.writeOnly(false)
.valueOf().writeOnly
).toEqual(false)
).toBe(false)
})
})

Expand Down Expand Up @@ -511,7 +511,7 @@ describe('BaseSchema', () => {
it('not an array', () => {
expect(() => {
return BaseSchema().allOf('test')
}).toThrowError(
}).toThrow(
new S.FluentSchemaError(
"'allOf' must be a an array of FluentSchema rather than a 'string'"
)
Expand All @@ -520,7 +520,7 @@ describe('BaseSchema', () => {
it('not an array of FluentSchema', () => {
expect(() => {
return BaseSchema().allOf(['test'])
}).toThrowError(
}).toThrow(
new S.FluentSchemaError(
"'allOf' must be a an array of FluentSchema rather than a 'object'"
)
Expand Down Expand Up @@ -570,7 +570,7 @@ describe('BaseSchema', () => {
it('not an array', () => {
expect(() => {
return BaseSchema().anyOf('test')
}).toThrowError(
}).toThrow(
new S.FluentSchemaError(
"'anyOf' must be a an array of FluentSchema rather than a 'string'"
)
Expand All @@ -579,7 +579,7 @@ describe('BaseSchema', () => {
it('not an array of FluentSchema', () => {
expect(() => {
return BaseSchema().anyOf(['test'])
}).toThrowError(
}).toThrow(
new S.FluentSchemaError(
"'anyOf' must be a an array of FluentSchema rather than a 'object'"
)
Expand All @@ -602,7 +602,7 @@ describe('BaseSchema', () => {
it('not an array', () => {
expect(() => {
return BaseSchema().oneOf('test')
}).toThrowError(
}).toThrow(
new S.FluentSchemaError(
"'oneOf' must be a an array of FluentSchema rather than a 'string'"
)
Expand All @@ -611,7 +611,7 @@ describe('BaseSchema', () => {
it('not an array of FluentSchema', () => {
expect(() => {
return BaseSchema().oneOf(['test'])
}).toThrowError(
}).toThrow(
new S.FluentSchemaError(
"'oneOf' must be a an array of FluentSchema rather than a 'object'"
)
Expand Down Expand Up @@ -648,7 +648,7 @@ describe('BaseSchema', () => {
it('invalid', () => {
expect(() => {
BaseSchema().not(undefined)
}).toThrowError(new S.FluentSchemaError("'not' must be a BaseSchema"))
}).toThrow(new S.FluentSchemaError("'not' must be a BaseSchema"))
})
})
})
Expand Down Expand Up @@ -703,14 +703,14 @@ describe('BaseSchema', () => {
undefined,
BaseSchema().description('A User desc')
)
}).toThrowError(
}).toThrow(
new S.FluentSchemaError("'ifClause' must be a BaseSchema")
)
})
it('thenClause', () => {
expect(() => {
BaseSchema().ifThen(BaseSchema().id('id'), undefined)
}).toThrowError(
}).toThrow(
new S.FluentSchemaError("'thenClause' must be a BaseSchema")
)
})
Expand Down Expand Up @@ -774,7 +774,7 @@ describe('BaseSchema', () => {
BaseSchema().description('then'),
BaseSchema().description('else')
)
}).toThrowError(
}).toThrow(
new S.FluentSchemaError("'ifClause' must be a BaseSchema")
)
})
Expand All @@ -785,7 +785,7 @@ describe('BaseSchema', () => {
undefined,
BaseSchema().description('else')
)
}).toThrowError(
}).toThrow(
new S.FluentSchemaError("'thenClause' must be a BaseSchema")
)
})
Expand All @@ -796,7 +796,7 @@ describe('BaseSchema', () => {
BaseSchema().description('then'),
undefined
)
}).toThrowError(
}).toThrow(
new S.FluentSchemaError(
"'elseClause' must be a BaseSchema or a false boolean value"
)
Expand Down
2 changes: 1 addition & 1 deletion src/BooleanSchema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('BooleanSchema', () => {
S.object()
.prop('prop', S.boolean())
.valueOf().properties.prop.type
).toEqual('boolean')
).toBe('boolean')
})

describe('raw', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/FluentSchema.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('S', () => {
state: 'Disney World',
type: 'business'
})
expect(validate.errors).toEqual(null)
expect(validate.errors).toBeNull()
expect(valid).toBeTruthy()
})
})
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('S', () => {

it('valid', () => {
const valid = validate({ foo: 'foo' })
expect(validate.errors).toEqual(null)
expect(validate.errors).toBeNull()
expect(valid).toBeTruthy()
})
})
Expand Down Expand Up @@ -326,7 +326,7 @@ describe('S', () => {
thenBarA: 'thenBarA',
thenBarB: 'thenBarB'
})
expect(validate.errors).toEqual(null)
expect(validate.errors).toBeNull()
expect(valid).toBeTruthy()
})
})
Expand Down Expand Up @@ -495,7 +495,7 @@ describe('S', () => {
const valid = validate({
test: null
})
expect(validate.errors).toEqual(null)
expect(validate.errors).toBeNull()
expect(valid).toBeTruthy()
})
})
Expand Down
Loading

0 comments on commit ac0085d

Please sign in to comment.