( check: Check, context? : TestCheckContext) => Check
defineTestCheck
wraps your checks and decorates these functions with sensible defaults for the CheckContext
that is passed to your message , validate and fix functions that you can override.
This cuts down on repetitive boilerplate when writing tests for your checks.
Parameters
The Check object that you want to test
An object containing metadata about the package the check is being run against.
Show check-context-properties
The tags that you want to test the check with
The codeowners that you want to test the check with
An object containing paths to the root directory of the package being checked.
A fully qualified path to the package directory
A relative path to the package directory relative to the root of the project
An object containing paths to the root directory of the current project.
A fully qualified path to the package directory
A relative path to the package directory relative to the root of the project
An array of objects containing paths to every package directory in the current project.
A fully qualified path to the package directory
A relative path to the package directory relative to the root of the project
Returns
Returns the original check function, however the validate
, fix
, and message
functions
will be passed the defaults in TestCheckContext
rather than requiring that all properties CheckContext
are explicitly passed when testing check methods.
Example
test ( 'validate - returns true when valid' , ( ) => {
mockFs ( {
'package.json' : JSON . stringify ( {
name: 'foo' ,
description: 'bar' ,
} ) ,
} ) ;
const check = myCheck ( ) ;
const result = myCheck. validate ( {
package : {
path: './' ,
relativePath: './' ,
} ,
allPackages: [
{
path: './' ,
relativePath: './' ,
} ,
] ,
codeowners: [ ] ,
tags: [ ] ,
} ) ;
expect ( result) . toEqual ( true ) ;
} ) ;
test ( 'validate - returns true when valid' , ( ) => {
mockFs ( {
'package.json' : JSON . stringify ( {
name: 'foo' ,
description: 'bar' ,
} ) ,
} ) ;
const check = defineTestCheck ( myCheck ( ) ) ;
const result = myCheck. validate ( ) ;
expect ( result) . toEqual ( true ) ;
} ) ;