├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .prettierignore ├── .prettierrc ├── .travis.yml ├── .yarnrc ├── .yo-rc.json ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── global.d.ts ├── jasmine.json ├── jest.config.js ├── lerna.json ├── package.json ├── packages ├── expect-more-jasmine │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── index.ts │ │ ├── lib │ │ │ └── get-in.ts │ │ ├── to-be-after.ts │ │ ├── to-be-array-including-all-of.ts │ │ ├── to-be-array-including-any-of.ts │ │ ├── to-be-array-including-only.ts │ │ ├── to-be-array-of-booleans.ts │ │ ├── to-be-array-of-numbers.ts │ │ ├── to-be-array-of-objects.ts │ │ ├── to-be-array-of-size.ts │ │ ├── to-be-array-of-strings.ts │ │ ├── to-be-array.ts │ │ ├── to-be-async-function.ts │ │ ├── to-be-before.ts │ │ ├── to-be-boolean.ts │ │ ├── to-be-calculable.ts │ │ ├── to-be-date-between.ts │ │ ├── to-be-date-in-month.ts │ │ ├── to-be-date-in-year.ts │ │ ├── to-be-date-on-day-of-month.ts │ │ ├── to-be-date-on-day-of-week.ts │ │ ├── to-be-date-on-or-after.ts │ │ ├── to-be-date-on-or-before.ts │ │ ├── to-be-date.ts │ │ ├── to-be-decimal-number.ts │ │ ├── to-be-divisible-by.ts │ │ ├── to-be-empty-array.ts │ │ ├── to-be-empty-object.ts │ │ ├── to-be-empty-string.ts │ │ ├── to-be-even-number.ts │ │ ├── to-be-function.ts │ │ ├── to-be-generator-function.ts │ │ ├── to-be-iso8601.ts │ │ ├── to-be-json-string.ts │ │ ├── to-be-longer-than.ts │ │ ├── to-be-negative-number.ts │ │ ├── to-be-nil.ts │ │ ├── to-be-non-empty-array.ts │ │ ├── to-be-non-empty-object.ts │ │ ├── to-be-non-empty-string.ts │ │ ├── to-be-number.ts │ │ ├── to-be-object.ts │ │ ├── to-be-odd-number.ts │ │ ├── to-be-positive-number.ts │ │ ├── to-be-reg-exp.ts │ │ ├── to-be-same-length-as.ts │ │ ├── to-be-shorter-than.ts │ │ ├── to-be-string.ts │ │ ├── to-be-valid-date.ts │ │ ├── to-be-visible-string.ts │ │ ├── to-be-walkable.ts │ │ ├── to-be-whitespace.ts │ │ ├── to-be-whole-number.ts │ │ ├── to-be-within-range.ts │ │ ├── to-end-with.ts │ │ ├── to-have-array-including-all-of.ts │ │ ├── to-have-array-including-any-of.ts │ │ ├── to-have-array-including-only.ts │ │ ├── to-have-array-of-booleans.ts │ │ ├── to-have-array-of-numbers.ts │ │ ├── to-have-array-of-objects.ts │ │ ├── to-have-array-of-size.ts │ │ ├── to-have-array-of-strings.ts │ │ ├── to-have-array.ts │ │ ├── to-have-async-function.ts │ │ ├── to-have-boolean.ts │ │ ├── to-have-calculable.ts │ │ ├── to-have-date-after.ts │ │ ├── to-have-date-before.ts │ │ ├── to-have-date-between.ts │ │ ├── to-have-date-in-month.ts │ │ ├── to-have-date-in-year.ts │ │ ├── to-have-date-on-day-of-month.ts │ │ ├── to-have-date-on-day-of-week.ts │ │ ├── to-have-date-on-or-after.ts │ │ ├── to-have-date-on-or-before.ts │ │ ├── to-have-date.ts │ │ ├── to-have-decimal-number.ts │ │ ├── to-have-divisible-by.ts │ │ ├── to-have-empty-array.ts │ │ ├── to-have-empty-object.ts │ │ ├── to-have-empty-string.ts │ │ ├── to-have-ending-with.ts │ │ ├── to-have-even-number.ts │ │ ├── to-have-false.ts │ │ ├── to-have-generator-function.ts │ │ ├── to-have-greater-than-or-equal-to.ts │ │ ├── to-have-iso8601.ts │ │ ├── to-have-json-string.ts │ │ ├── to-have-less-than-or-equal-to.ts │ │ ├── to-have-longer-than.ts │ │ ├── to-have-method.ts │ │ ├── to-have-negative-number.ts │ │ ├── to-have-nil.ts │ │ ├── to-have-non-empty-array.ts │ │ ├── to-have-non-empty-object.ts │ │ ├── to-have-non-empty-string.ts │ │ ├── to-have-null.ts │ │ ├── to-have-number-near.ts │ │ ├── to-have-number-within-range.ts │ │ ├── to-have-number.ts │ │ ├── to-have-object.ts │ │ ├── to-have-odd-number.ts │ │ ├── to-have-positive-number.ts │ │ ├── to-have-reg-exp.ts │ │ ├── to-have-same-length-as.ts │ │ ├── to-have-shorter-than.ts │ │ ├── to-have-starting-with.ts │ │ ├── to-have-string.ts │ │ ├── to-have-true.ts │ │ ├── to-have-undefined.ts │ │ ├── to-have-valid-date.ts │ │ ├── to-have-visible-string.ts │ │ ├── to-have-walkable.ts │ │ ├── to-have-whitespace.ts │ │ ├── to-have-whole-number.ts │ │ └── to-start-with.ts │ ├── test │ │ ├── to-be-after.spec.ts │ │ ├── to-be-array-including-all-of.spec.ts │ │ ├── to-be-array-including-any-of.spec.ts │ │ ├── to-be-array-including-only.spec.ts │ │ ├── to-be-array-of-booleans.spec.ts │ │ ├── to-be-array-of-numbers.spec.ts │ │ ├── to-be-array-of-objects.spec.ts │ │ ├── to-be-array-of-size.spec.ts │ │ ├── to-be-array-of-strings.spec.ts │ │ ├── to-be-array.spec.ts │ │ ├── to-be-async-function.spec.ts │ │ ├── to-be-before.spec.ts │ │ ├── to-be-boolean.spec.ts │ │ ├── to-be-calculable.spec.ts │ │ ├── to-be-date-between.spec.ts │ │ ├── to-be-date-in-month.spec.ts │ │ ├── to-be-date-in-year.spec.ts │ │ ├── to-be-date-on-day-of-month.spec.ts │ │ ├── to-be-date-on-day-of-week.spec.ts │ │ ├── to-be-date-on-or-after.spec.ts │ │ ├── to-be-date-on-or-before.spec.ts │ │ ├── to-be-date.spec.ts │ │ ├── to-be-decimal-number.spec.ts │ │ ├── to-be-divisible-by.spec.ts │ │ ├── to-be-empty-array.spec.ts │ │ ├── to-be-empty-object.spec.ts │ │ ├── to-be-empty-string.spec.ts │ │ ├── to-be-even-number.spec.ts │ │ ├── to-be-function.spec.ts │ │ ├── to-be-generator-function.spec.ts │ │ ├── to-be-iso8601.spec.ts │ │ ├── to-be-json-string.spec.ts │ │ ├── to-be-longer-than.spec.ts │ │ ├── to-be-negative-number.spec.ts │ │ ├── to-be-nil.spec.ts │ │ ├── to-be-non-empty-array.spec.ts │ │ ├── to-be-non-empty-object.spec.ts │ │ ├── to-be-non-empty-string.spec.ts │ │ ├── to-be-number.spec.ts │ │ ├── to-be-object.spec.ts │ │ ├── to-be-odd-number.spec.ts │ │ ├── to-be-positive-number.spec.ts │ │ ├── to-be-reg-exp.spec.ts │ │ ├── to-be-same-length-as.spec.ts │ │ ├── to-be-shorter-than.spec.ts │ │ ├── to-be-string.spec.ts │ │ ├── to-be-valid-date.spec.ts │ │ ├── to-be-visible-string.spec.ts │ │ ├── to-be-walkable.spec.ts │ │ ├── to-be-whitespace.spec.ts │ │ ├── to-be-whole-number.spec.ts │ │ ├── to-be-within-range.spec.ts │ │ ├── to-end-with.spec.ts │ │ ├── to-have-array-including-all-of.spec.ts │ │ ├── to-have-array-including-any-of.spec.ts │ │ ├── to-have-array-including-only.spec.ts │ │ ├── to-have-array-of-booleans.spec.ts │ │ ├── to-have-array-of-numbers.spec.ts │ │ ├── to-have-array-of-objects.spec.ts │ │ ├── to-have-array-of-size.spec.ts │ │ ├── to-have-array-of-strings.spec.ts │ │ ├── to-have-array.spec.ts │ │ ├── to-have-async-function.spec.ts │ │ ├── to-have-boolean.spec.ts │ │ ├── to-have-calculable.spec.ts │ │ ├── to-have-date-after.spec.ts │ │ ├── to-have-date-before.spec.ts │ │ ├── to-have-date-between.spec.ts │ │ ├── to-have-date-in-month.spec.ts │ │ ├── to-have-date-in-year.spec.ts │ │ ├── to-have-date-on-day-of-month.spec.ts │ │ ├── to-have-date-on-day-of-week.spec.ts │ │ ├── to-have-date-on-or-after.spec.ts │ │ ├── to-have-date-on-or-before.spec.ts │ │ ├── to-have-date.spec.ts │ │ ├── to-have-decimal-number.spec.ts │ │ ├── to-have-divisible-by.spec.ts │ │ ├── to-have-empty-array.spec.ts │ │ ├── to-have-empty-object.spec.ts │ │ ├── to-have-empty-string.spec.ts │ │ ├── to-have-ending-with.spec.ts │ │ ├── to-have-even-number.spec.ts │ │ ├── to-have-false.spec.ts │ │ ├── to-have-generator-function.spec.ts │ │ ├── to-have-greater-than-or-equal-to.spec.ts │ │ ├── to-have-iso8601.spec.ts │ │ ├── to-have-json-string.spec.ts │ │ ├── to-have-less-than-or-equal-to.spec.ts │ │ ├── to-have-longer-than.spec.ts │ │ ├── to-have-method.spec.ts │ │ ├── to-have-negative-number.spec.ts │ │ ├── to-have-nil.spec.ts │ │ ├── to-have-non-empty-array.spec.ts │ │ ├── to-have-non-empty-object.spec.ts │ │ ├── to-have-non-empty-string.spec.ts │ │ ├── to-have-null.spec.ts │ │ ├── to-have-number-near.spec.ts │ │ ├── to-have-number-within-range.spec.ts │ │ ├── to-have-number.spec.ts │ │ ├── to-have-object.spec.ts │ │ ├── to-have-odd-number.spec.ts │ │ ├── to-have-positive-number.spec.ts │ │ ├── to-have-reg-exp.spec.ts │ │ ├── to-have-same-length-as.spec.ts │ │ ├── to-have-shorter-than.spec.ts │ │ ├── to-have-starting-with.spec.ts │ │ ├── to-have-string.spec.ts │ │ ├── to-have-true.spec.ts │ │ ├── to-have-undefined.spec.ts │ │ ├── to-have-valid-date.spec.ts │ │ ├── to-have-visible-string.spec.ts │ │ ├── to-have-walkable.spec.ts │ │ ├── to-have-whitespace.spec.ts │ │ ├── to-have-whole-number.spec.ts │ │ └── to-start-with.spec.ts │ └── tsconfig.json ├── expect-more-jest │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ │ ├── index.ts │ │ ├── lib │ │ │ ├── create-result.ts │ │ │ └── get-in.ts │ │ ├── to-be-after.ts │ │ ├── to-be-array-including-all-of.ts │ │ ├── to-be-array-including-any-of.ts │ │ ├── to-be-array-including-only.ts │ │ ├── to-be-array-of-booleans.ts │ │ ├── to-be-array-of-numbers.ts │ │ ├── to-be-array-of-objects.ts │ │ ├── to-be-array-of-size.ts │ │ ├── to-be-array-of-strings.ts │ │ ├── to-be-array-of.ts │ │ ├── to-be-array.ts │ │ ├── to-be-async-function.ts │ │ ├── to-be-before.ts │ │ ├── to-be-boolean.ts │ │ ├── to-be-calculable.ts │ │ ├── to-be-date-between.ts │ │ ├── to-be-date-in-month.ts │ │ ├── to-be-date-in-year.ts │ │ ├── to-be-date-on-day-of-month.ts │ │ ├── to-be-date-on-day-of-week.ts │ │ ├── to-be-date-on-or-after.ts │ │ ├── to-be-date-on-or-before.ts │ │ ├── to-be-date.ts │ │ ├── to-be-decimal-number.ts │ │ ├── to-be-divisible-by.ts │ │ ├── to-be-empty-array.ts │ │ ├── to-be-empty-object.ts │ │ ├── to-be-empty-string.ts │ │ ├── to-be-even-number.ts │ │ ├── to-be-false.ts │ │ ├── to-be-function.ts │ │ ├── to-be-generator-function.ts │ │ ├── to-be-iso8601.ts │ │ ├── to-be-json-string.ts │ │ ├── to-be-longer-than.ts │ │ ├── to-be-negative-number.ts │ │ ├── to-be-nil.ts │ │ ├── to-be-non-empty-array.ts │ │ ├── to-be-non-empty-object.ts │ │ ├── to-be-non-empty-string.ts │ │ ├── to-be-nullable-of.ts │ │ ├── to-be-number.ts │ │ ├── to-be-object.ts │ │ ├── to-be-odd-number.ts │ │ ├── to-be-optional-of.ts │ │ ├── to-be-positive-number.ts │ │ ├── to-be-reg-exp.ts │ │ ├── to-be-same-length-as.ts │ │ ├── to-be-shorter-than.ts │ │ ├── to-be-string.ts │ │ ├── to-be-true.ts │ │ ├── to-be-valid-date.ts │ │ ├── to-be-visible-string.ts │ │ ├── to-be-walkable.ts │ │ ├── to-be-whitespace.ts │ │ ├── to-be-whole-number.ts │ │ ├── to-be-within-range.ts │ │ ├── to-end-with.ts │ │ └── to-start-with.ts │ ├── test │ │ ├── issue-35.spec.ts │ │ ├── to-be-after.spec.ts │ │ ├── to-be-array-including-all-of.spec.ts │ │ ├── to-be-array-including-any-of.spec.ts │ │ ├── to-be-array-including-only.spec.ts │ │ ├── to-be-array-of-booleans.spec.ts │ │ ├── to-be-array-of-numbers.spec.ts │ │ ├── to-be-array-of-objects.spec.ts │ │ ├── to-be-array-of-size.spec.ts │ │ ├── to-be-array-of-strings.spec.ts │ │ ├── to-be-array-of.spec.ts │ │ ├── to-be-array.spec.ts │ │ ├── to-be-async-function.spec.ts │ │ ├── to-be-before.spec.ts │ │ ├── to-be-boolean.spec.ts │ │ ├── to-be-calculable.spec.ts │ │ ├── to-be-date-between.spec.ts │ │ ├── to-be-date-in-month.spec.ts │ │ ├── to-be-date-in-year.spec.ts │ │ ├── to-be-date-on-day-of-month.spec.ts │ │ ├── to-be-date-on-day-of-week.spec.ts │ │ ├── to-be-date-on-or-after.spec.ts │ │ ├── to-be-date-on-or-before.spec.ts │ │ ├── to-be-date.spec.ts │ │ ├── to-be-decimal-number.spec.ts │ │ ├── to-be-divisible-by.spec.ts │ │ ├── to-be-empty-array.spec.ts │ │ ├── to-be-empty-object.spec.ts │ │ ├── to-be-empty-string.spec.ts │ │ ├── to-be-even-number.spec.ts │ │ ├── to-be-false.spec.ts │ │ ├── to-be-function.spec.ts │ │ ├── to-be-generator-function.spec.ts │ │ ├── to-be-iso8601.spec.ts │ │ ├── to-be-json-string.spec.ts │ │ ├── to-be-longer-than.spec.ts │ │ ├── to-be-negative-number.spec.ts │ │ ├── to-be-nil.spec.ts │ │ ├── to-be-non-empty-array.spec.ts │ │ ├── to-be-non-empty-object.spec.ts │ │ ├── to-be-non-empty-string.spec.ts │ │ ├── to-be-nullable-of.spec.ts │ │ ├── to-be-number.spec.ts │ │ ├── to-be-object.spec.ts │ │ ├── to-be-odd-number.spec.ts │ │ ├── to-be-optional-of.spec.ts │ │ ├── to-be-positive-number.spec.ts │ │ ├── to-be-reg-exp.spec.ts │ │ ├── to-be-same-length-as.spec.ts │ │ ├── to-be-shorter-than.spec.ts │ │ ├── to-be-string.spec.ts │ │ ├── to-be-true.spec.ts │ │ ├── to-be-valid-date.spec.ts │ │ ├── to-be-visible-string.spec.ts │ │ ├── to-be-walkable.spec.ts │ │ ├── to-be-whitespace.spec.ts │ │ ├── to-be-whole-number.spec.ts │ │ ├── to-be-within-range.spec.ts │ │ ├── to-end-with.spec.ts │ │ └── to-start-with.spec.ts │ └── tsconfig.json └── expect-more │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ ├── src │ ├── ends-with.ts │ ├── gen │ │ ├── index.ts │ │ ├── lib.ts │ │ ├── with-missing-branches.ts │ │ ├── with-missing-leaves.ts │ │ ├── with-missing-nodes.ts │ │ ├── with-null-branches.ts │ │ ├── with-null-leaves.ts │ │ └── with-null-nodes.ts │ ├── has-member.ts │ ├── index.ts │ ├── is-after.ts │ ├── is-array-including-all-of.ts │ ├── is-array-including-any-of.ts │ ├── is-array-including-only.ts │ ├── is-array-of-booleans.ts │ ├── is-array-of-numbers.ts │ ├── is-array-of-objects.ts │ ├── is-array-of-size.ts │ ├── is-array-of-strings.ts │ ├── is-array.ts │ ├── is-async-function.ts │ ├── is-before.ts │ ├── is-boolean.ts │ ├── is-calculable.ts │ ├── is-date-between.ts │ ├── is-date-in-month.ts │ ├── is-date-in-year.ts │ ├── is-date-on-day-of-month.ts │ ├── is-date-on-day-of-week.ts │ ├── is-date-on-or-after.ts │ ├── is-date-on-or-before.ts │ ├── is-date.ts │ ├── is-decimal-number.ts │ ├── is-divisible-by.ts │ ├── is-empty-array.ts │ ├── is-empty-object.ts │ ├── is-empty-string.ts │ ├── is-even-number.ts │ ├── is-false.ts │ ├── is-function.ts │ ├── is-generator-function.ts │ ├── is-greater-than-or-equal-to.ts │ ├── is-iso-8601.ts │ ├── is-json-string.ts │ ├── is-less-than-or-equal-to.ts │ ├── is-longer-than.ts │ ├── is-near.ts │ ├── is-negative-number.ts │ ├── is-nil.ts │ ├── is-non-empty-array.ts │ ├── is-non-empty-object.ts │ ├── is-non-empty-string.ts │ ├── is-null.ts │ ├── is-number.ts │ ├── is-object.ts │ ├── is-odd-number.ts │ ├── is-positive-number.ts │ ├── is-reg-exp.ts │ ├── is-same-length-as.ts │ ├── is-shorter-than.ts │ ├── is-string.ts │ ├── is-true.ts │ ├── is-undefined.ts │ ├── is-valid-date.ts │ ├── is-visible-string.ts │ ├── is-walkable.ts │ ├── is-whitespace.ts │ ├── is-whole-number.ts │ ├── is-within-range.ts │ ├── lib │ │ ├── curry1.ts │ │ ├── curry2.ts │ │ ├── curry3.ts │ │ ├── every.ts │ │ ├── get-type.ts │ │ ├── has-type.ts │ │ ├── is-asym.ts │ │ ├── is-indexed-list.ts │ │ ├── is-jest-equal.ts │ │ ├── keys.ts │ │ └── some.ts │ ├── starts-with.ts │ ├── throws-any-error.ts │ ├── throws-error-of-type.ts │ └── typings.ts │ ├── test │ ├── ends-with.spec.ts │ ├── gen │ │ ├── index.spec.ts │ │ ├── with-missing-branches.spec.ts │ │ ├── with-missing-leaves.spec.ts │ │ ├── with-missing-nodes.spec.ts │ │ ├── with-null-branches.spec.ts │ │ ├── with-null-leaves.spec.ts │ │ └── with-null-nodes.spec.ts │ ├── has-member.spec.ts │ ├── is-array-including-all-of.spec.ts │ ├── is-array-including-any-of.spec.ts │ ├── is-array-including-only.spec.ts │ ├── is-array-of-booleans.spec.ts │ ├── is-array-of-numbers.spec.ts │ ├── is-array-of-objects.spec.ts │ ├── is-array-of-size.spec.ts │ ├── is-array-of-strings.spec.ts │ ├── is-array.spec.ts │ ├── is-async-function.spec.ts │ ├── is-boolean.spec.ts │ ├── is-calculable.spec.ts │ ├── is-date-after.spec.ts │ ├── is-date-before.spec.ts │ ├── is-date-between.spec.ts │ ├── is-date-in-month.spec.ts │ ├── is-date-in-year.spec.ts │ ├── is-date-on-day-of-month.spec.ts │ ├── is-date-on-day-of-week.spec.ts │ ├── is-date-on-or-after.spec.ts │ ├── is-date-on-or-before.spec.ts │ ├── is-date.spec.ts │ ├── is-decimal-number.spec.ts │ ├── is-divisible-by.spec.ts │ ├── is-empty-array.spec.ts │ ├── is-empty-object.spec.ts │ ├── is-empty-string.spec.ts │ ├── is-even-number.spec.ts │ ├── is-false.spec.ts │ ├── is-function.spec.ts │ ├── is-generator-function.spec.ts │ ├── is-greater-than-or-equal-to.spec.ts │ ├── is-iso8601.spec.ts │ ├── is-json-string.spec.ts │ ├── is-less-than-or-equal-to.spec.ts │ ├── is-longer-than.spec.ts │ ├── is-near.spec.ts │ ├── is-negative-number.spec.ts │ ├── is-nil.spec.ts │ ├── is-non-empty-array.spec.ts │ ├── is-non-empty-object.spec.ts │ ├── is-non-empty-string.spec.ts │ ├── is-number.spec.ts │ ├── is-object.spec.ts │ ├── is-odd-number.spec.ts │ ├── is-positive-number.spec.ts │ ├── is-reg-exp.spec.ts │ ├── is-same-length-as.spec.ts │ ├── is-shorter-than.spec.ts │ ├── is-string.spec.ts │ ├── is-true.spec.ts │ ├── is-undefined.spec.ts │ ├── is-valid-date.spec.ts │ ├── is-visible-string.spec.ts │ ├── is-walkable.spec.ts │ ├── is-whitespace.spec.ts │ ├── is-whole-number.spec.ts │ ├── is-within-range.spec.ts │ ├── lib │ │ └── curry.spec.ts │ ├── starts-with.spec.ts │ ├── throws-any-error.spec.ts │ └── throws-error-of-type.spec.ts │ └── tsconfig.json ├── scripts ├── generate-docs.ts ├── generate-matchers.sh ├── generate-matchers │ ├── index.ts │ ├── jasmine-index.ts │ ├── jasmine-matcher-test.ts │ ├── jasmine-matcher.ts │ ├── jasmine-member-matcher-test.ts │ ├── jasmine-member-matcher.ts │ ├── jest-index.ts │ ├── jest-matcher-test.ts │ ├── jest-matcher.ts │ └── paths.ts └── tsconfig.json ├── test ├── fixtures │ ├── index.ts │ ├── negative.ts │ └── positive.ts ├── jasmine-helper.ts └── setup-test-framework-script-file.ts ├── tsconfig.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_size = 2 6 | indent_style = space 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | packages/*/dist 3 | packages/*/node_modules 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | plugins: ['@typescript-eslint'], 4 | extends: [ 5 | // 'eslint:recommended', 6 | 'plugin:@typescript-eslint/recommended', 7 | 'plugin:prettier/recommended', 8 | ], 9 | parserOptions: { 10 | ecmaVersion: 6, 11 | sourceType: 'module', 12 | }, 13 | env: { 14 | es6: true, 15 | node: true, 16 | }, 17 | rules: { 18 | // for intellisense, we have to extend the jest namespace 19 | '@typescript-eslint/no-namespace': 0, 20 | 'no-redeclare': 0, 21 | // we don't know what permutations users will pass to `expect` 22 | '@typescript-eslint/no-explicit-any': 0, 23 | '@typescript-eslint/explicit-function-return-type': 0, 24 | }, 25 | overrides: [ 26 | { 27 | files: ['packages/expect-more-jest/*/*.ts', '*.spec.ts'], 28 | env: { 29 | jest: true, 30 | }, 31 | }, 32 | ], 33 | }; 34 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: JamieMason 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Explain how to reproduce a Bug 4 | --- 5 | 6 | ## Description 7 | 8 | 13 | 14 | ## Suggested Solution 15 | 16 | 20 | 21 | ## Help Needed 22 | 23 | 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | --- 5 | 6 | ## Description 7 | 8 | 14 | 15 | ## Suggested Solution 16 | 17 | 21 | 22 | ## Help Needed 23 | 24 | 28 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Description (What) 2 | 3 | 9 | 10 | ## Justification (Why) 11 | 12 | 18 | 19 | ## How Can This Be Tested? 20 | 21 | 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.log.* 3 | coverage 4 | dist 5 | node_modules 6 | package-lock.json 7 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | **/CHANGELOG.md 2 | **/README.md 3 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "always", 3 | "printWidth": 100, 4 | "proseWrap": "always", 5 | "singleQuote": true, 6 | "trailingComma": "all" 7 | } 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | env: 2 | global: 3 | - CC_TEST_REPORTER_ID=d89a1aab357b12d8de6b1592d16fa766e2dddf8e3c5e5064f5333ab8444e5382 4 | language: node_js 5 | matrix: 6 | fast_finish: true 7 | node_js: 8 | - 16.13.1 9 | before_script: 10 | - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > 11 | ./codeclimate-test-reporter 12 | - chmod +x ./codeclimate-test-reporter 13 | - ./codeclimate-test-reporter before-build 14 | - yarn build 15 | script: 16 | - yarn lint 17 | - yarn test --maxWorkers=4 18 | after_script: 19 | - ./codeclimate-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT 20 | -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | save-prefix false 2 | -------------------------------------------------------------------------------- /.yo-rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "generator-expect-more": { 3 | "assertion": { 4 | "camelName": "isWithinRange", 5 | "hasArguments": false, 6 | "rawArguments": "floor: number, ceiling: number" 7 | }, 8 | "matcher": { 9 | "camelName": "toBeWithinRange", 10 | "description": "Asserts that a value is a `Number` which is both greater than or equal to `floor` and less than or equal to `ceiling`.", 11 | "hasArguments": false, 12 | "rawArguments": "floor: number, ceiling: number", 13 | "example": "expect(6).toBeWithinRange(1, 10);", 14 | "asymmetricExample": "expect(onPress).toHaveBeenCalledWith(expect.toBeWithinRange(1, 10))", 15 | "failMessage": "expected ${received} to be within range ${floor} - ${ceiling} (inclusive)", 16 | "notFailMessage": "expected ${received} not to be within range ${floor} - ${ceiling} (inclusive)" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Jamie Mason 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /global.d.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | import 'jasmine-check'; 3 | -------------------------------------------------------------------------------- /jasmine.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_dir": "packages/expect-more-jasmine/test", 3 | "spec_files": ["**/*.spec.ts"], 4 | "helpers": [], 5 | "stopSpecOnExpectationFailure": false, 6 | "random": true 7 | } 8 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "command": { 3 | "init": { 4 | "exact": true 5 | }, 6 | "publish": { 7 | "conventionalCommits": true, 8 | "exact": true 9 | } 10 | }, 11 | "independent": true, 12 | "lerna": "3.18.3", 13 | "npmClient": "yarn", 14 | "packages": ["packages/*", "scripts/*"], 15 | "useWorkspaces": true, 16 | "version": "independent" 17 | } 18 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "expect-more-jasmine", 3 | "description": "Write Beautiful Specs with Custom Matchers for Jasmine", 4 | "version": "0.5.0", 5 | "author": "Jamie Mason (https://github.com/JamieMason)", 6 | "bugs": "https://github.com/JamieMason/expect-more/issues", 7 | "contributors": [], 8 | "dependencies": { 9 | "expect-more": "1.3.0", 10 | "jest-matcher-utils": "29.4.1" 11 | }, 12 | "files": [ 13 | "dist" 14 | ], 15 | "homepage": "https://github.com/JamieMason/expect-more/tree/master/packages/expect-more-jasmine/#readme", 16 | "keywords": [ 17 | "assertions", 18 | "ava", 19 | "bdd", 20 | "expect", 21 | "jasmine", 22 | "jest", 23 | "matchers", 24 | "mocha", 25 | "mock", 26 | "spy", 27 | "tdd", 28 | "test", 29 | "test-matchers", 30 | "testing", 31 | "unit" 32 | ], 33 | "license": "MIT", 34 | "main": "dist/index.js", 35 | "repository": "JamieMason/expect-more", 36 | "scripts": { 37 | "prepublish": "cd ../../ && npm run build:expect-more-jasmine" 38 | }, 39 | "typings": "./dist/index.d.ts" 40 | } 41 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/lib/get-in.ts: -------------------------------------------------------------------------------- 1 | import { isWalkable } from 'expect-more'; 2 | 3 | export const getIn = (path: (string | number)[], origin: Record | any[]) => 4 | path.reduce((parent, child) => (isWalkable(parent) ? parent[child] : undefined), origin); 5 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-array.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isArray } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is a valid `Array` containing none or any number of items of any type. 12 | * @example 13 | * expect([2, true, 'string']).toBeArray(); 14 | */ 15 | toBeArray(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeArrayMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isArray(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be an array` 26 | : `expected ${printReceived(value)} to be an array`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeArray: toBeArrayMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-date.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isDate } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is an instance of `Date`. 12 | * @example 13 | * expect(new Date('2019-12-31')).toBeDate(); 14 | */ 15 | toBeDate(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeDateMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isDate(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be an instance of Date` 26 | : `expected ${printReceived(value)} to be an instance of Date`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeDate: toBeDateMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-empty-array.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isEmptyArray } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is a valid `Array` containing no items. 12 | * @example 13 | * expect([]).toBeEmptyArray(); 14 | */ 15 | toBeEmptyArray(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeEmptyArrayMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isEmptyArray(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be an array containing no items` 26 | : `expected ${printReceived(value)} to be an array containing no items`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeEmptyArray: toBeEmptyArrayMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-empty-object.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isEmptyObject } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is a valid `Object` containing no instance members. 12 | * @example 13 | * expect({}).toBeEmptyObject(); 14 | */ 15 | toBeEmptyObject(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeEmptyObjectMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isEmptyObject(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be an empty object` 26 | : `expected ${printReceived(value)} to be an empty object`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeEmptyObject: toBeEmptyObjectMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-even-number.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isEvenNumber } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is an even `Number`. 12 | * @example 13 | * expect(2).toBeEvenNumber(); 14 | */ 15 | toBeEvenNumber(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeEvenNumberMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isEvenNumber(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be an even number` 26 | : `expected ${printReceived(value)} to be an even number`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeEvenNumber: toBeEvenNumberMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-function.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isFunction } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is a `Function`. 12 | * @example 13 | * expect(() => 'i am a function').toBeFunction(); 14 | */ 15 | toBeFunction(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeFunctionMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isFunction(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be a function or async function` 26 | : `expected ${printReceived(value)} to be a function or async function`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeFunction: toBeFunctionMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-json-string.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isJsonString } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is a `String` of valid JSON. 12 | * @example 13 | * expect('{"i":"am valid JSON"}').toBeJsonString(); 14 | */ 15 | toBeJsonString(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeJsonStringMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isJsonString(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be a string of valid JSON` 26 | : `expected ${printReceived(value)} to be a string of valid JSON`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeJsonString: toBeJsonStringMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-negative-number.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isNegativeNumber } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is a `Number` less than 0. 12 | * @example 13 | * expect(-18).toBeNegativeNumber(); 14 | */ 15 | toBeNegativeNumber(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeNegativeNumberMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isNegativeNumber(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be a negative number` 26 | : `expected ${printReceived(value)} to be a negative number`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeNegativeNumber: toBeNegativeNumberMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-nil.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isNil } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is `null` or `undefined` 12 | * @example 13 | * expect(undefined).toBeNil(); 14 | */ 15 | toBeNil(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeNilMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isNil(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be null or undefined` 26 | : `expected ${printReceived(value)} to be null or undefined`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeNil: toBeNilMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-number.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isNumber } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is a valid `Number` or `new Number()` and not `NaN`. 12 | * @example 13 | * expect(8).toBeNumber(); 14 | */ 15 | toBeNumber(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeNumberMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isNumber(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be a valid number` 26 | : `expected ${printReceived(value)} to be a valid number`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeNumber: toBeNumberMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-object.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isObject } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is an `Object`. 12 | * @example 13 | * expect({}).toBeObject(); 14 | */ 15 | toBeObject(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeObjectMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isObject(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be an object` 26 | : `expected ${printReceived(value)} to be an object`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeObject: toBeObjectMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-odd-number.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isOddNumber } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is an odd `Number`. 12 | * @example 13 | * expect(5).toBeOddNumber(); 14 | */ 15 | toBeOddNumber(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeOddNumberMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isOddNumber(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be an odd number` 26 | : `expected ${printReceived(value)} to be an odd number`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeOddNumber: toBeOddNumberMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-positive-number.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isPositiveNumber } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is a `Number` greater than 0. 12 | * @example 13 | * expect(5).toBePositiveNumber(); 14 | */ 15 | toBePositiveNumber(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBePositiveNumberMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isPositiveNumber(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be a positive number` 26 | : `expected ${printReceived(value)} to be a positive number`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBePositiveNumber: toBePositiveNumberMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-reg-exp.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isRegExp } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is a `RegExp`. 12 | * @example 13 | * expect(new RegExp('i am a regular expression')).toBeRegExp(); 14 | */ 15 | toBeRegExp(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeRegExpMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isRegExp(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be a regular expression` 26 | : `expected ${printReceived(value)} to be a regular expression`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeRegExp: toBeRegExpMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-string.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isString } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is a `String` or `new String()`. 12 | * @example 13 | * expect('i am a string').toBeString(); 14 | */ 15 | toBeString(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeStringMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isString(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be a string` 26 | : `expected ${printReceived(value)} to be a string`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeString: toBeStringMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-walkable.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isWalkable } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is safe to attempt to read property values from. 12 | * @example 13 | * expect({}).toBeWalkable(); 14 | */ 15 | toBeWalkable(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeWalkableMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isWalkable(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be walkable` 26 | : `expected ${printReceived(value)} to be walkable`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeWalkable: toBeWalkableMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/src/to-be-whole-number.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isWholeNumber } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | 6 | declare global { 7 | namespace jasmine { 8 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is a `Number` with no positive decimal places. 12 | * @example 13 | * expect(8).toBeWholeNumber(); 14 | */ 15 | toBeWholeNumber(): boolean; 16 | } 17 | } 18 | } 19 | 20 | export const toBeWholeNumberMatcher: jasmine.CustomMatcherFactory = () => { 21 | return { 22 | compare(value: unknown) { 23 | const pass = isWholeNumber(value); 24 | const message = pass 25 | ? `expected ${printReceived(value)} not to be a whole number` 26 | : `expected ${printReceived(value)} to be a whole number`; 27 | return { message, pass }; 28 | }, 29 | }; 30 | }; 31 | 32 | beforeAll(() => { 33 | jasmine.addMatchers({ 34 | toBeWholeNumber: toBeWholeNumberMatcher, 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-after.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeAfter()', () => { 5 | expect(new Date('2020-01-01')).toBeAfter(new Date('2019-12-31')); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-array-including-all-of.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeArrayIncludingAllOf()', () => { 5 | expect([12, 0, 14, 'Ivo']).toBeArrayIncludingAllOf(['Ivo', 14]); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-array-including-any-of.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeArrayIncludingAnyOf()', () => { 5 | expect([12, 0, 14, 'Ginola']).toBeArrayIncludingAnyOf(['Ginola', 3]); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-array-including-only.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeArrayIncludingOnly()', () => { 5 | expect([5, 10, 1]).toBeArrayIncludingOnly([1, 5, 10]); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-array-of-booleans.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeArrayOfBooleans()', () => { 5 | expect([true, false, new Boolean(true)]).toBeArrayOfBooleans(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-array-of-numbers.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeArrayOfNumbers()', () => { 5 | expect([12, 0, 14]).toBeArrayOfNumbers(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-array-of-objects.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeArrayOfObjects()', () => { 5 | expect([{}, new Object()]).toBeArrayOfObjects(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-array-of-size.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeArrayOfSize()', () => { 5 | expect(['i', 'contain', 4, 'items']).toBeArrayOfSize(4); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-array-of-strings.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeArrayOfStrings()', () => { 5 | expect(['we', 'are', 'all', 'strings']).toBeArrayOfStrings(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-array.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeArray()', () => { 5 | expect([2, true, 'string']).toBeArray(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-async-function.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | // eval is workaround for typescript converting async to non-async 5 | 6 | it('provides expect().toBeAsyncFunction()', () => { 7 | expect(eval('(async (_) => _)')).toBeAsyncFunction(); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-before.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeBefore()', () => { 5 | expect(new Date('2019-12-31')).toBeBefore(new Date('2020-01-01')); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-boolean.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeBoolean()', () => { 5 | expect(false).toBeBoolean(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-calculable.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeCalculable()', () => { 5 | expect('100').toBeCalculable(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-date-between.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeDateBetween()', () => { 5 | expect(new Date('2019-12-11')).toBeDateBetween(new Date('2019-12-10'), new Date('2019-12-12')); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-date-in-month.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeDateInMonth()', () => { 5 | expect(new Date('2021-08-29')).toBeDateInMonth(7); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-date-in-year.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeDateInYear()', () => { 5 | expect(new Date('2021-08-29')).toBeDateInYear(2021); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-date-on-day-of-month.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeDateOnDayOfMonth()', () => { 5 | expect(new Date('2021-08-29')).toBeDateOnDayOfMonth(29); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-date-on-day-of-week.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeDateOnDayOfWeek()', () => { 5 | expect(new Date('2021-08-29')).toBeDateOnDayOfWeek(0); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-date-on-or-after.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeDateOnOrAfter()', () => { 5 | expect(new Date('2019-12-31')).toBeDateOnOrAfter(new Date('2019-12-15')); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-date-on-or-before.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeDateOnOrBefore()', () => { 5 | expect(new Date('2019-12-15')).toBeDateOnOrBefore(new Date('2019-12-31')); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-date.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeDate()', () => { 5 | expect(new Date('2019-12-31')).toBeDate(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-decimal-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeDecimalNumber()', () => { 5 | expect(12.55).toBeDecimalNumber(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-divisible-by.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeDivisibleBy()', () => { 5 | expect(12).toBeDivisibleBy(2); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-empty-array.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeEmptyArray()', () => { 5 | expect([]).toBeEmptyArray(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-empty-object.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeEmptyObject()', () => { 5 | expect({}).toBeEmptyObject(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-empty-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeEmptyString()', () => { 5 | expect('').toBeEmptyString(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-even-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeEvenNumber()', () => { 5 | expect(2).toBeEvenNumber(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-function.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeFunction()', () => { 5 | expect(() => 'i am a function').toBeFunction(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-generator-function.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | // eval is workaround for typescript converting generator fns 5 | 6 | it('provides expect().toBeGeneratorFunction()', () => { 7 | expect(eval('(function*() {yield 2;})')).toBeGeneratorFunction(); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-iso8601.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeIso8601()', () => { 5 | expect('1999-12-31T23:59:59').toBeIso8601(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-json-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeJsonString()', () => { 5 | expect('{"i":"am valid JSON"}').toBeJsonString(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-longer-than.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeLongerThan()', () => { 5 | expect(['i', 'have', 3]).toBeLongerThan([2, 'items']); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-negative-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeNegativeNumber()', () => { 5 | expect(-18).toBeNegativeNumber(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-nil.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeNil()', () => { 5 | expect(undefined).toBeNil(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-non-empty-array.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeNonEmptyArray()', () => { 5 | expect(['i', 'am not empty']).toBeNonEmptyArray(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-non-empty-object.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeNonEmptyObject()', () => { 5 | expect({ i: 'am not empty' }).toBeNonEmptyObject(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-non-empty-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeNonEmptyString()', () => { 5 | expect('i am not empty').toBeNonEmptyString(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeNumber()', () => { 5 | expect(8).toBeNumber(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-object.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeObject()', () => { 5 | expect({}).toBeObject(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-odd-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeOddNumber()', () => { 5 | expect(5).toBeOddNumber(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-positive-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBePositiveNumber()', () => { 5 | expect(5).toBePositiveNumber(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-reg-exp.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeRegExp()', () => { 5 | expect(new RegExp('i am a regular expression')).toBeRegExp(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-same-length-as.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeSameLengthAs()', () => { 5 | expect(['i also have', '2 items']).toBeSameLengthAs(['i have', '2 items']); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-shorter-than.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeShorterThan()', () => { 5 | expect(['i have one item']).toBeShorterThan(['i', 'have', 4, 'items']); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeString()', () => { 5 | expect('i am a string').toBeString(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-valid-date.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeValidDate()', () => { 5 | expect(new Date('2020-01-01')).toBeValidDate(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-visible-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeVisibleString()', () => { 5 | expect('i am visible').toBeVisibleString(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-walkable.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeWalkable()', () => { 5 | expect({}).toBeWalkable(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-whitespace.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeWhitespace()', () => { 5 | expect(' ').toBeWhitespace(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-whole-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeWholeNumber()', () => { 5 | expect(8).toBeWholeNumber(); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-be-within-range.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toBeWithinRange()', () => { 5 | expect(7).toBeWithinRange(0, 10); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-end-with.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toEndWith()', () => { 5 | expect('JavaScript').toEndWith('Script'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-array-including-all-of.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveArrayIncludingAllOf()', () => { 5 | expect({ child: { grandchild: [12, 0, 14, 'Ivo'] } }).toHaveArrayIncludingAllOf( 6 | 'child.grandchild', 7 | ['Ivo', 14], 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-array-including-any-of.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveArrayIncludingAnyOf()', () => { 5 | expect({ child: { grandchild: [12, 0, 14, 'Ginola'] } }).toHaveArrayIncludingAnyOf( 6 | 'child.grandchild', 7 | ['Ginola', 3], 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-array-including-only.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveArrayIncludingOnly()', () => { 5 | expect({ child: { grandchild: [5, 10, 1] } }).toHaveArrayIncludingOnly( 6 | 'child.grandchild', 7 | [1, 5, 10], 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-array-of-booleans.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveArrayOfBooleans()', () => { 5 | expect({ child: { grandchild: [true, false, new Boolean(true)] } }).toHaveArrayOfBooleans( 6 | 'child.grandchild', 7 | ); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-array-of-numbers.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveArrayOfNumbers()', () => { 5 | expect({ child: { grandchild: [12, 0, 14] } }).toHaveArrayOfNumbers('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-array-of-objects.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveArrayOfObjects()', () => { 5 | expect({ child: { grandchild: [{}, new Object()] } }).toHaveArrayOfObjects('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-array-of-size.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveArrayOfSize()', () => { 5 | expect({ child: { grandchild: ['i', 'contain', 4, 'items'] } }).toHaveArrayOfSize( 6 | 'child.grandchild', 7 | 4, 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-array-of-strings.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveArrayOfStrings()', () => { 5 | expect({ child: { grandchild: ['we', 'are', 'all', 'strings'] } }).toHaveArrayOfStrings( 6 | 'child.grandchild', 7 | ); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-array.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveArray()', () => { 5 | expect({ child: { grandchild: [2, true, 'string'] } }).toHaveArray('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-async-function.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | // eval is workaround for typescript converting async to non-async 5 | 6 | it('provides expect().toHaveAsyncFunction()', () => { 7 | expect({ child: { grandchild: eval('(async (_) => _)') } }).toHaveAsyncFunction( 8 | 'child.grandchild', 9 | ); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-boolean.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveBoolean()', () => { 5 | expect({ child: { grandchild: false } }).toHaveBoolean('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-calculable.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveCalculable()', () => { 5 | expect({ child: { grandchild: '100' } }).toHaveCalculable('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-date-after.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveDateAfter()', () => { 5 | expect({ child: { grandchild: new Date('2020-01-01') } }).toHaveDateAfter( 6 | 'child.grandchild', 7 | new Date('2019-12-31'), 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-date-before.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveDateBefore()', () => { 5 | expect({ child: { grandchild: new Date('2019-12-31') } }).toHaveDateBefore( 6 | 'child.grandchild', 7 | new Date('2020-01-01'), 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-date-between.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveDateBetween()', () => { 5 | expect({ child: { grandchild: new Date('2019-12-11') } }).toHaveDateBetween( 6 | 'child.grandchild', 7 | new Date('2019-12-10'), 8 | new Date('2019-12-12'), 9 | ); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-date-in-month.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveDateInMonth()', () => { 5 | expect({ child: { grandchild: new Date('2021-08-29') } }).toHaveDateInMonth( 6 | 'child.grandchild', 7 | 7, 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-date-in-year.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveDateInYear()', () => { 5 | expect({ child: { grandchild: new Date('2021-08-29') } }).toHaveDateInYear( 6 | 'child.grandchild', 7 | 2021, 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-date-on-day-of-month.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveDateOnDayOfMonth()', () => { 5 | expect({ child: { grandchild: new Date('2021-08-29') } }).toHaveDateOnDayOfMonth( 6 | 'child.grandchild', 7 | 29, 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-date-on-day-of-week.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveDateOnDayOfWeek()', () => { 5 | expect({ child: { grandchild: new Date('2021-08-29') } }).toHaveDateOnDayOfWeek( 6 | 'child.grandchild', 7 | 0, 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-date-on-or-after.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveDateOnOrAfter()', () => { 5 | expect({ child: { grandchild: new Date('2019-12-31') } }).toHaveDateOnOrAfter( 6 | 'child.grandchild', 7 | new Date('2019-12-15'), 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-date-on-or-before.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveDateOnOrBefore()', () => { 5 | expect({ child: { grandchild: new Date('2019-12-15') } }).toHaveDateOnOrBefore( 6 | 'child.grandchild', 7 | new Date('2019-12-31'), 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-date.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveDate()', () => { 5 | expect({ child: { grandchild: new Date('2019-12-31') } }).toHaveDate('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-decimal-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveDecimalNumber()', () => { 5 | expect({ child: { grandchild: 12.55 } }).toHaveDecimalNumber('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-divisible-by.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveDivisibleBy()', () => { 5 | expect({ child: { grandchild: 12 } }).toHaveDivisibleBy('child.grandchild', 2); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-empty-array.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveEmptyArray()', () => { 5 | expect({ child: { grandchild: [] } }).toHaveEmptyArray('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-empty-object.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveEmptyObject()', () => { 5 | expect({ child: { grandchild: {} } }).toHaveEmptyObject('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-empty-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveEmptyString()', () => { 5 | expect({ child: { grandchild: '' } }).toHaveEmptyString('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-ending-with.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveEndingWith()', () => { 5 | expect({ child: { grandchild: 'JavaScript' } }).toHaveEndingWith('child.grandchild', 'Script'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-even-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveEvenNumber()', () => { 5 | expect({ child: { grandchild: 2 } }).toHaveEvenNumber('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-false.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveFalse()', () => { 5 | expect({ child: { grandchild: false } }).toHaveFalse('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-generator-function.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | // eval is workaround for typescript converting generator fns 5 | 6 | it('provides expect().toHaveGeneratorFunction()', () => { 7 | expect({ child: { grandchild: eval('(function*() {yield 2;})') } }).toHaveGeneratorFunction( 8 | 'child.grandchild', 9 | ); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-greater-than-or-equal-to.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveGreaterThanOrEqualTo()', () => { 5 | expect({ child: { grandchild: 10 } }).toHaveGreaterThanOrEqualTo('child.grandchild', 5); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-iso8601.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveIso8601()', () => { 5 | expect({ child: { grandchild: '1999-12-31T23:59:59' } }).toHaveIso8601('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-json-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveJsonString()', () => { 5 | expect({ child: { grandchild: '{"i":"am valid JSON"}' } }).toHaveJsonString('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-less-than-or-equal-to.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveLessThanOrEqualTo()', () => { 5 | expect({ child: { grandchild: 8 } }).toHaveLessThanOrEqualTo('child.grandchild', 12); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-longer-than.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveLongerThan()', () => { 5 | expect({ child: { grandchild: ['i', 'have', 3] } }).toHaveLongerThan('child.grandchild', [ 6 | 2, 7 | 'items', 8 | ]); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-method.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveMethod()', () => { 5 | expect({ child: { grandchild: () => 'i am a function' } }).toHaveMethod('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-negative-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveNegativeNumber()', () => { 5 | expect({ child: { grandchild: -18 } }).toHaveNegativeNumber('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-nil.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveNil()', () => { 5 | expect({ child: { grandchild: undefined } }).toHaveNil('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-non-empty-array.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveNonEmptyArray()', () => { 5 | expect({ child: { grandchild: ['i', 'am not empty'] } }).toHaveNonEmptyArray('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-non-empty-object.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveNonEmptyObject()', () => { 5 | expect({ child: { grandchild: { i: 'am not empty' } } }).toHaveNonEmptyObject('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-non-empty-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveNonEmptyString()', () => { 5 | expect({ child: { grandchild: 'i am not empty' } }).toHaveNonEmptyString('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-null.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveNull()', () => { 5 | expect({ child: { grandchild: null } }).toHaveNull('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-number-near.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveNumberNear()', () => { 5 | expect({ child: { grandchild: 4.8 } }).toHaveNumberNear('child.grandchild', 5, 0.5); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-number-within-range.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveNumberWithinRange()', () => { 5 | expect({ child: { grandchild: 7 } }).toHaveNumberWithinRange('child.grandchild', 0, 10); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveNumber()', () => { 5 | expect({ child: { grandchild: 8 } }).toHaveNumber('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-object.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveObject()', () => { 5 | expect({ child: { grandchild: {} } }).toHaveObject('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-odd-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveOddNumber()', () => { 5 | expect({ child: { grandchild: 5 } }).toHaveOddNumber('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-positive-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHavePositiveNumber()', () => { 5 | expect({ child: { grandchild: 5 } }).toHavePositiveNumber('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-reg-exp.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveRegExp()', () => { 5 | expect({ child: { grandchild: new RegExp('i am a regular expression') } }).toHaveRegExp( 6 | 'child.grandchild', 7 | ); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-same-length-as.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveSameLengthAs()', () => { 5 | expect({ child: { grandchild: ['i also have', '2 items'] } }).toHaveSameLengthAs( 6 | 'child.grandchild', 7 | ['i have', '2 items'], 8 | ); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-shorter-than.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveShorterThan()', () => { 5 | expect({ child: { grandchild: ['i have one item'] } }).toHaveShorterThan('child.grandchild', [ 6 | 'i', 7 | 'have', 8 | 4, 9 | 'items', 10 | ]); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-starting-with.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveStartingWith()', () => { 5 | expect({ child: { grandchild: 'JavaScript' } }).toHaveStartingWith('child.grandchild', 'Java'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveString()', () => { 5 | expect({ child: { grandchild: 'i am a string' } }).toHaveString('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-true.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveTrue()', () => { 5 | expect({ child: { grandchild: true } }).toHaveTrue('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-undefined.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveUndefined()', () => { 5 | expect({ child: { grandchild: undefined } }).toHaveUndefined('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-valid-date.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveValidDate()', () => { 5 | expect({ child: { grandchild: new Date('2020-01-01') } }).toHaveValidDate('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-visible-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveVisibleString()', () => { 5 | expect({ child: { grandchild: 'i am visible' } }).toHaveVisibleString('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-walkable.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveWalkable()', () => { 5 | expect({ child: { grandchild: {} } }).toHaveWalkable('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-whitespace.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveWhitespace()', () => { 5 | expect({ child: { grandchild: ' ' } }).toHaveWhitespace('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-have-whole-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toHaveWholeNumber()', () => { 5 | expect({ child: { grandchild: 8 } }).toHaveWholeNumber('child.grandchild'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/test/to-start-with.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jasmine'; 2 | import 'jasmine'; 3 | 4 | it('provides expect().toStartWith()', () => { 5 | expect('JavaScript').toStartWith('Java'); 6 | }); 7 | -------------------------------------------------------------------------------- /packages/expect-more-jasmine/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "files": ["./src/index.ts"], 4 | "compilerOptions": { 5 | "esModuleInterop": true, 6 | "outDir": "./dist" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/expect-more-jest/src/lib/create-result.ts: -------------------------------------------------------------------------------- 1 | export const createResult = ({ 2 | pass, 3 | message, 4 | notMessage, 5 | }: { 6 | pass: boolean; 7 | message: () => string; 8 | notMessage: () => string; 9 | }): jest.CustomMatcherResult => ({ 10 | message: () => (pass ? notMessage() : message()).trim(), 11 | pass, 12 | }); 13 | -------------------------------------------------------------------------------- /packages/expect-more-jest/src/lib/get-in.ts: -------------------------------------------------------------------------------- 1 | import { isWalkable } from 'expect-more'; 2 | 3 | export const getIn = (path: (string | number)[], origin: Record | any[]) => 4 | path.reduce((parent, child) => (isWalkable(parent) ? parent[child] : undefined), origin); 5 | -------------------------------------------------------------------------------- /packages/expect-more-jest/src/to-be-nil.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isNil } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | import { createResult } from './lib/create-result'; 6 | 7 | declare global { 8 | namespace jest { 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is `null` or `undefined` 12 | * @example 13 | * expect(undefined).toBeNil(); 14 | */ 15 | toBeNil(): R; 16 | } 17 | interface Expect { 18 | /** 19 | * Asserts that a value is `null` or `undefined` 20 | * @example 21 | * expect(undefined).toEqual( 22 | * expect.toBeNil() 23 | * ); 24 | */ 25 | toBeNil(): JestMatchers; 26 | } 27 | } 28 | } 29 | 30 | export const toBeNilMatcher = (value: unknown): jest.CustomMatcherResult => 31 | createResult({ 32 | message: () => `expected ${printReceived(value)} to be null or undefined`, 33 | notMessage: () => `expected ${printReceived(value)} not to be null or undefined`, 34 | pass: isNil(value), 35 | }); 36 | 37 | expect.extend({ toBeNil: toBeNilMatcher }); 38 | -------------------------------------------------------------------------------- /packages/expect-more-jest/src/to-be-object.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { isObject } from 'expect-more'; 4 | import { printReceived } from 'jest-matcher-utils'; 5 | import { createResult } from './lib/create-result'; 6 | 7 | declare global { 8 | namespace jest { 9 | interface Matchers { 10 | /** 11 | * Asserts that a value is an `Object`. 12 | * @example 13 | * expect({}).toBeObject(); 14 | */ 15 | toBeObject(): R; 16 | } 17 | interface Expect { 18 | /** 19 | * Asserts that a value is an `Object`. 20 | * @example 21 | * expect({}).toEqual( 22 | * expect.toBeObject() 23 | * ); 24 | */ 25 | toBeObject(): JestMatchers; 26 | } 27 | } 28 | } 29 | 30 | export const toBeObjectMatcher = (value: unknown): jest.CustomMatcherResult => 31 | createResult({ 32 | message: () => `expected ${printReceived(value)} to be an object`, 33 | notMessage: () => `expected ${printReceived(value)} not to be an object`, 34 | pass: isObject(value), 35 | }); 36 | 37 | expect.extend({ toBeObject: toBeObjectMatcher }); 38 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/issue-35.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | describe('when a test subject contains an object with no prototype', () => { 4 | describe('when the test fails (array has 1 item not 8)', () => { 5 | it('should construct matcher test failure messages correctly', () => { 6 | try { 7 | expect.assertions(3); 8 | expect([Object.create(null)]).toBeArrayOfSize(8); 9 | } catch (err) { 10 | expect(err.message).toContain('to be an array containing exactly'); 11 | expect(err.message).not.toContain('Cannot convert object to primitive value'); 12 | } 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-after.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeAfter()', () => { 4 | expect(new Date('2020-01-01')).toBeAfter(new Date('2019-12-31')); 5 | }); 6 | 7 | it('provides expect().not.toBeAfter()', () => { 8 | expect(() => expect(new Date('2020-01-01')).not.toBeAfter(new Date('2019-12-31'))).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeAfter()', () => { 12 | expect(new Date('2020-01-01')).toEqual(expect.toBeAfter(new Date('2019-12-31'))); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-array-including-all-of.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeArrayIncludingAllOf()', () => { 4 | expect([12, 0, 14, 'Ivo']).toBeArrayIncludingAllOf(['Ivo', 14]); 5 | }); 6 | 7 | it('provides expect().not.toBeArrayIncludingAllOf()', () => { 8 | expect(() => expect([12, 0, 14, 'Ivo']).not.toBeArrayIncludingAllOf(['Ivo', 14])).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeArrayIncludingAllOf()', () => { 12 | expect([12, 0, 14, 'Ivo']).toEqual(expect.toBeArrayIncludingAllOf(['Ivo', 14])); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-array-including-any-of.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeArrayIncludingAnyOf()', () => { 4 | expect([12, 0, 14, 'Ginola']).toBeArrayIncludingAnyOf(['Ginola', 3]); 5 | }); 6 | 7 | it('provides expect().not.toBeArrayIncludingAnyOf()', () => { 8 | expect(() => expect([12, 0, 14, 'Ginola']).not.toBeArrayIncludingAnyOf(['Ginola', 3])).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeArrayIncludingAnyOf()', () => { 12 | expect([12, 0, 14, 'Ginola']).toEqual(expect.toBeArrayIncludingAnyOf(['Ginola', 3])); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-array-including-only.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeArrayIncludingOnly()', () => { 4 | expect([5, 10, 1]).toBeArrayIncludingOnly([1, 5, 10]); 5 | }); 6 | 7 | it('provides expect().not.toBeArrayIncludingOnly()', () => { 8 | expect(() => expect([5, 10, 1]).not.toBeArrayIncludingOnly([1, 5, 10])).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeArrayIncludingOnly()', () => { 12 | expect([5, 10, 1]).toEqual(expect.toBeArrayIncludingOnly([1, 5, 10])); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-array-of-booleans.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeArrayOfBooleans()', () => { 4 | expect([true, false, new Boolean(true)]).toBeArrayOfBooleans(); 5 | }); 6 | 7 | it('provides expect().not.toBeArrayOfBooleans()', () => { 8 | expect(() => expect([true, false, new Boolean(true)]).not.toBeArrayOfBooleans()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeArrayOfBooleans()', () => { 12 | expect([true, false, new Boolean(true)]).toEqual(expect.toBeArrayOfBooleans()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-array-of-numbers.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeArrayOfNumbers()', () => { 4 | expect([12, 0, 14]).toBeArrayOfNumbers(); 5 | }); 6 | 7 | it('provides expect().not.toBeArrayOfNumbers()', () => { 8 | expect(() => expect([12, 0, 14]).not.toBeArrayOfNumbers()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeArrayOfNumbers()', () => { 12 | expect([12, 0, 14]).toEqual(expect.toBeArrayOfNumbers()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-array-of-objects.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeArrayOfObjects()', () => { 4 | expect([{}, new Object()]).toBeArrayOfObjects(); 5 | }); 6 | 7 | it('provides expect().not.toBeArrayOfObjects()', () => { 8 | expect(() => expect([{}, new Object()]).not.toBeArrayOfObjects()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeArrayOfObjects()', () => { 12 | expect([{}, new Object()]).toEqual(expect.toBeArrayOfObjects()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-array-of-size.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeArrayOfSize()', () => { 4 | expect(['i', 'contain', 4, 'items']).toBeArrayOfSize(4); 5 | }); 6 | 7 | it('provides expect().not.toBeArrayOfSize()', () => { 8 | expect(() => expect(['i', 'contain', 4, 'items']).not.toBeArrayOfSize(4)).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeArrayOfSize()', () => { 12 | expect(['i', 'contain', 4, 'items']).toEqual(expect.toBeArrayOfSize(4)); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-array-of-strings.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeArrayOfStrings()', () => { 4 | expect(['we', 'are', 'all', 'strings']).toBeArrayOfStrings(); 5 | }); 6 | 7 | it('provides expect().not.toBeArrayOfStrings()', () => { 8 | expect(() => expect(['we', 'are', 'all', 'strings']).not.toBeArrayOfStrings()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeArrayOfStrings()', () => { 12 | expect(['we', 'are', 'all', 'strings']).toEqual(expect.toBeArrayOfStrings()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-array-of.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeArrayOf()', () => { 4 | expect([ 5 | { name: 'Guybrush', age: 20 }, 6 | { name: 'Elaine', age: 22 }, 7 | ]).toBeArrayOf({ 8 | name: expect.toBeNonEmptyString(), 9 | age: expect.toBeWithinRange(20, 30), 10 | }); 11 | }); 12 | 13 | it('provides expect().not.toBeArrayOf()', () => { 14 | expect([true, false, 'i am not a boolean']).not.toBeArrayOf(expect.toBeBoolean()); 15 | expect(() => 16 | expect([{ name: 'Guybrush' }, { name: 'Elaine' }]).not.toBeArrayOf({ 17 | name: expect.toBeNonEmptyString(), 18 | }), 19 | ).toThrow(); 20 | }); 21 | 22 | it('provides expect.toBeArrayOf()', () => { 23 | expect([{ name: 'Guybrush' }, { name: 'Elaine' }]).toEqual( 24 | expect.toBeArrayOf({ name: expect.toBeNonEmptyString() }), 25 | ); 26 | }); 27 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-array.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeArray()', () => { 4 | expect([2, true, 'string']).toBeArray(); 5 | }); 6 | 7 | it('provides expect().not.toBeArray()', () => { 8 | expect(() => expect([2, true, 'string']).not.toBeArray()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeArray()', () => { 12 | expect([2, true, 'string']).toEqual(expect.toBeArray()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-async-function.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | // eval is workaround for typescript converting async to non-async 3 | 4 | it('provides expect().toBeAsyncFunction()', () => { 5 | expect(eval('(async (_) => _)')).toBeAsyncFunction(); 6 | }); 7 | 8 | it('provides expect().not.toBeAsyncFunction()', () => { 9 | expect(() => expect(eval('(async (_) => _)')).not.toBeAsyncFunction()).toThrow(); 10 | }); 11 | 12 | it('provides expect.toBeAsyncFunction()', () => { 13 | expect(eval('(async (_) => _)')).toEqual(expect.toBeAsyncFunction()); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-before.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeBefore()', () => { 4 | expect(new Date('2019-12-31')).toBeBefore(new Date('2020-01-01')); 5 | }); 6 | 7 | it('provides expect().not.toBeBefore()', () => { 8 | expect(() => expect(new Date('2019-12-31')).not.toBeBefore(new Date('2020-01-01'))).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeBefore()', () => { 12 | expect(new Date('2019-12-31')).toEqual(expect.toBeBefore(new Date('2020-01-01'))); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-boolean.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeBoolean()', () => { 4 | expect(false).toBeBoolean(); 5 | }); 6 | 7 | it('provides expect().not.toBeBoolean()', () => { 8 | expect(() => expect(false).not.toBeBoolean()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeBoolean()', () => { 12 | expect(false).toEqual(expect.toBeBoolean()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-calculable.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeCalculable()', () => { 4 | expect('100').toBeCalculable(); 5 | }); 6 | 7 | it('provides expect().not.toBeCalculable()', () => { 8 | expect(() => expect('100').not.toBeCalculable()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeCalculable()', () => { 12 | expect('100').toEqual(expect.toBeCalculable()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-date-between.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeDateBetween()', () => { 4 | expect(new Date('2019-12-11')).toBeDateBetween(new Date('2019-12-10'), new Date('2019-12-12')); 5 | }); 6 | 7 | it('provides expect().not.toBeDateBetween()', () => { 8 | expect(() => 9 | expect(new Date('2019-12-11')).not.toBeDateBetween( 10 | new Date('2019-12-10'), 11 | new Date('2019-12-12'), 12 | ), 13 | ).toThrow(); 14 | }); 15 | 16 | it('provides expect.toBeDateBetween()', () => { 17 | expect(new Date('2019-12-11')).toEqual( 18 | expect.toBeDateBetween(new Date('2019-12-10'), new Date('2019-12-12')), 19 | ); 20 | }); 21 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-date-in-month.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeDateInMonth()', () => { 4 | expect(new Date('2021-08-29')).toBeDateInMonth(7); 5 | }); 6 | 7 | it('provides expect().not.toBeDateInMonth()', () => { 8 | expect(() => expect(new Date('2021-08-29')).not.toBeDateInMonth(7)).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeDateInMonth()', () => { 12 | expect(new Date('2021-08-29')).toEqual(expect.toBeDateInMonth(7)); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-date-in-year.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeDateInYear()', () => { 4 | expect(new Date('2021-08-29')).toBeDateInYear(2021); 5 | }); 6 | 7 | it('provides expect().not.toBeDateInYear()', () => { 8 | expect(() => expect(new Date('2021-08-29')).not.toBeDateInYear(2021)).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeDateInYear()', () => { 12 | expect(new Date('2021-08-29')).toEqual(expect.toBeDateInYear(2021)); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-date-on-day-of-month.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeDateOnDayOfMonth()', () => { 4 | expect(new Date('2021-08-29')).toBeDateOnDayOfMonth(29); 5 | }); 6 | 7 | it('provides expect().not.toBeDateOnDayOfMonth()', () => { 8 | expect(() => expect(new Date('2021-08-29')).not.toBeDateOnDayOfMonth(29)).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeDateOnDayOfMonth()', () => { 12 | expect(new Date('2021-08-29')).toEqual(expect.toBeDateOnDayOfMonth(29)); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-date-on-day-of-week.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeDateOnDayOfWeek()', () => { 4 | expect(new Date('2021-08-29')).toBeDateOnDayOfWeek(0); 5 | }); 6 | 7 | it('provides expect().not.toBeDateOnDayOfWeek()', () => { 8 | expect(() => expect(new Date('2021-08-29')).not.toBeDateOnDayOfWeek(0)).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeDateOnDayOfWeek()', () => { 12 | expect(new Date('2021-08-29')).toEqual(expect.toBeDateOnDayOfWeek(0)); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-date-on-or-after.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeDateOnOrAfter()', () => { 4 | expect(new Date('2019-12-31')).toBeDateOnOrAfter(new Date('2019-12-15')); 5 | }); 6 | 7 | it('provides expect().not.toBeDateOnOrAfter()', () => { 8 | expect(() => 9 | expect(new Date('2019-12-31')).not.toBeDateOnOrAfter(new Date('2019-12-15')), 10 | ).toThrow(); 11 | }); 12 | 13 | it('provides expect.toBeDateOnOrAfter()', () => { 14 | expect(new Date('2019-12-31')).toEqual(expect.toBeDateOnOrAfter(new Date('2019-12-15'))); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-date-on-or-before.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeDateOnOrBefore()', () => { 4 | expect(new Date('2019-12-15')).toBeDateOnOrBefore(new Date('2019-12-31')); 5 | }); 6 | 7 | it('provides expect().not.toBeDateOnOrBefore()', () => { 8 | expect(() => 9 | expect(new Date('2019-12-15')).not.toBeDateOnOrBefore(new Date('2019-12-31')), 10 | ).toThrow(); 11 | }); 12 | 13 | it('provides expect.toBeDateOnOrBefore()', () => { 14 | expect(new Date('2019-12-15')).toEqual(expect.toBeDateOnOrBefore(new Date('2019-12-31'))); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-date.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeDate()', () => { 4 | expect(new Date('2019-12-31')).toBeDate(); 5 | }); 6 | 7 | it('provides expect().not.toBeDate()', () => { 8 | expect(() => expect(new Date('2019-12-31')).not.toBeDate()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeDate()', () => { 12 | expect(new Date('2019-12-31')).toEqual(expect.toBeDate()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-decimal-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeDecimalNumber()', () => { 4 | expect(12.55).toBeDecimalNumber(); 5 | }); 6 | 7 | it('provides expect().not.toBeDecimalNumber()', () => { 8 | expect(() => expect(12.55).not.toBeDecimalNumber()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeDecimalNumber()', () => { 12 | expect(12.55).toEqual(expect.toBeDecimalNumber()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-divisible-by.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeDivisibleBy()', () => { 4 | expect(12).toBeDivisibleBy(2); 5 | }); 6 | 7 | it('provides expect().not.toBeDivisibleBy()', () => { 8 | expect(() => expect(12).not.toBeDivisibleBy(2)).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeDivisibleBy()', () => { 12 | expect(12).toEqual(expect.toBeDivisibleBy(2)); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-empty-array.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeEmptyArray()', () => { 4 | expect([]).toBeEmptyArray(); 5 | }); 6 | 7 | it('provides expect().not.toBeEmptyArray()', () => { 8 | expect(() => expect([]).not.toBeEmptyArray()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeEmptyArray()', () => { 12 | expect([]).toEqual(expect.toBeEmptyArray()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-empty-object.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeEmptyObject()', () => { 4 | expect({}).toBeEmptyObject(); 5 | }); 6 | 7 | it('provides expect().not.toBeEmptyObject()', () => { 8 | expect(() => expect({}).not.toBeEmptyObject()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeEmptyObject()', () => { 12 | expect({}).toEqual(expect.toBeEmptyObject()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-empty-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeEmptyString()', () => { 4 | expect('').toBeEmptyString(); 5 | }); 6 | 7 | it('provides expect().not.toBeEmptyString()', () => { 8 | expect(() => expect('').not.toBeEmptyString()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeEmptyString()', () => { 12 | expect('').toEqual(expect.toBeEmptyString()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-even-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeEvenNumber()', () => { 4 | expect(2).toBeEvenNumber(); 5 | }); 6 | 7 | it('provides expect().not.toBeEvenNumber()', () => { 8 | expect(() => expect(2).not.toBeEvenNumber()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeEvenNumber()', () => { 12 | expect(2).toEqual(expect.toBeEvenNumber()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-false.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeFalse()', () => { 4 | expect(false).toBeFalse(); 5 | }); 6 | 7 | it('provides expect().not.toBeFalse()', () => { 8 | expect(() => expect(false).not.toBeFalse()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeFalse()', () => { 12 | expect(false).toEqual(expect.toBeFalse()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-function.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeFunction()', () => { 4 | expect(() => 'i am a function').toBeFunction(); 5 | }); 6 | 7 | it('provides expect().not.toBeFunction()', () => { 8 | expect(() => expect(() => 'i am a function').not.toBeFunction()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeFunction()', () => { 12 | expect(() => 'i am a function').toEqual(expect.toBeFunction()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-generator-function.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | // eval is workaround for typescript converting generator fns 3 | 4 | it('provides expect().toBeGeneratorFunction()', () => { 5 | expect(eval('(function*() {yield 2;})')).toBeGeneratorFunction(); 6 | }); 7 | 8 | it('provides expect().not.toBeGeneratorFunction()', () => { 9 | expect(() => expect(eval('(function*() {yield 2;})')).not.toBeGeneratorFunction()).toThrow(); 10 | }); 11 | 12 | it('provides expect.toBeGeneratorFunction()', () => { 13 | expect(eval('(function*() {yield 2;})')).toEqual(expect.toBeGeneratorFunction()); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-iso8601.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeIso8601()', () => { 4 | expect('1999-12-31T23:59:59').toBeIso8601(); 5 | }); 6 | 7 | it('provides expect().not.toBeIso8601()', () => { 8 | expect(() => expect('1999-12-31T23:59:59').not.toBeIso8601()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeIso8601()', () => { 12 | expect('1999-12-31T23:59:59').toEqual(expect.toBeIso8601()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-json-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeJsonString()', () => { 4 | expect('{"i":"am valid JSON"}').toBeJsonString(); 5 | }); 6 | 7 | it('provides expect().not.toBeJsonString()', () => { 8 | expect(() => expect('{"i":"am valid JSON"}').not.toBeJsonString()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeJsonString()', () => { 12 | expect('{"i":"am valid JSON"}').toEqual(expect.toBeJsonString()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-longer-than.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeLongerThan()', () => { 4 | expect(['i', 'have', 3]).toBeLongerThan([2, 'items']); 5 | }); 6 | 7 | it('provides expect().not.toBeLongerThan()', () => { 8 | expect(() => expect(['i', 'have', 3]).not.toBeLongerThan([2, 'items'])).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeLongerThan()', () => { 12 | expect(['i', 'have', 3]).toEqual(expect.toBeLongerThan([2, 'items'])); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-negative-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeNegativeNumber()', () => { 4 | expect(-18).toBeNegativeNumber(); 5 | }); 6 | 7 | it('provides expect().not.toBeNegativeNumber()', () => { 8 | expect(() => expect(-18).not.toBeNegativeNumber()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeNegativeNumber()', () => { 12 | expect(-18).toEqual(expect.toBeNegativeNumber()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-nil.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeNil()', () => { 4 | expect(undefined).toBeNil(); 5 | }); 6 | 7 | it('provides expect().not.toBeNil()', () => { 8 | expect(() => expect(undefined).not.toBeNil()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeNil()', () => { 12 | expect(undefined).toEqual(expect.toBeNil()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-non-empty-array.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeNonEmptyArray()', () => { 4 | expect(['i', 'am not empty']).toBeNonEmptyArray(); 5 | }); 6 | 7 | it('provides expect().not.toBeNonEmptyArray()', () => { 8 | expect(() => expect(['i', 'am not empty']).not.toBeNonEmptyArray()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeNonEmptyArray()', () => { 12 | expect(['i', 'am not empty']).toEqual(expect.toBeNonEmptyArray()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-non-empty-object.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeNonEmptyObject()', () => { 4 | expect({ i: 'am not empty' }).toBeNonEmptyObject(); 5 | }); 6 | 7 | it('provides expect().not.toBeNonEmptyObject()', () => { 8 | expect(() => expect({ i: 'am not empty' }).not.toBeNonEmptyObject()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeNonEmptyObject()', () => { 12 | expect({ i: 'am not empty' }).toEqual(expect.toBeNonEmptyObject()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-non-empty-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeNonEmptyString()', () => { 4 | expect('i am not empty').toBeNonEmptyString(); 5 | }); 6 | 7 | it('provides expect().not.toBeNonEmptyString()', () => { 8 | expect(() => expect('i am not empty').not.toBeNonEmptyString()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeNonEmptyString()', () => { 12 | expect('i am not empty').toEqual(expect.toBeNonEmptyString()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-nullable-of.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | const expectedShape = { 4 | x: expect.toBeNumber(), 5 | y: expect.toBeNumber(), 6 | }; 7 | 8 | it('provides expect().toBeNullableOf()', () => { 9 | expect({ x: 0, y: 12 }).toBeNullableOf(expectedShape); 10 | expect(null).toBeNullableOf(expectedShape); 11 | }); 12 | 13 | it('provides expect().not.toBeNullableOf()', () => { 14 | expect('mismatch').not.toBeNullableOf(expectedShape); 15 | expect(() => expect({ x: 0, y: 12 }).not.toBeNullableOf(expectedShape)).toThrow(); 16 | }); 17 | 18 | it('provides expect.toBeNullableOf()', () => { 19 | expect({ x: 0, y: 12 }).toEqual(expect.toBeNullableOf(expectedShape)); 20 | }); 21 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeNumber()', () => { 4 | expect(8).toBeNumber(); 5 | }); 6 | 7 | it('provides expect().not.toBeNumber()', () => { 8 | expect(() => expect(8).not.toBeNumber()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeNumber()', () => { 12 | expect(8).toEqual(expect.toBeNumber()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-object.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeObject()', () => { 4 | expect({}).toBeObject(); 5 | }); 6 | 7 | it('provides expect().not.toBeObject()', () => { 8 | expect(() => expect({}).not.toBeObject()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeObject()', () => { 12 | expect({}).toEqual(expect.toBeObject()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-odd-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeOddNumber()', () => { 4 | expect(5).toBeOddNumber(); 5 | }); 6 | 7 | it('provides expect().not.toBeOddNumber()', () => { 8 | expect(() => expect(5).not.toBeOddNumber()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeOddNumber()', () => { 12 | expect(5).toEqual(expect.toBeOddNumber()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-optional-of.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | const expectedShape = { 4 | x: expect.toBeNumber(), 5 | y: expect.toBeNumber(), 6 | }; 7 | 8 | it('provides expect().toBeOptionalOf()', () => { 9 | expect({ x: 0, y: 12 }).toBeOptionalOf(expectedShape); 10 | expect(undefined).toBeOptionalOf(expectedShape); 11 | }); 12 | 13 | it('provides expect().not.toBeOptionalOf()', () => { 14 | expect('mismatch').not.toBeOptionalOf(expectedShape); 15 | expect(() => expect({ x: 0, y: 12 }).not.toBeOptionalOf(expectedShape)).toThrow(); 16 | }); 17 | 18 | it('provides expect.toBeOptionalOf()', () => { 19 | expect({ x: 0, y: 12 }).toEqual(expect.toBeOptionalOf(expectedShape)); 20 | }); 21 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-positive-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBePositiveNumber()', () => { 4 | expect(5).toBePositiveNumber(); 5 | }); 6 | 7 | it('provides expect().not.toBePositiveNumber()', () => { 8 | expect(() => expect(5).not.toBePositiveNumber()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBePositiveNumber()', () => { 12 | expect(5).toEqual(expect.toBePositiveNumber()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-reg-exp.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeRegExp()', () => { 4 | expect(new RegExp('i am a regular expression')).toBeRegExp(); 5 | }); 6 | 7 | it('provides expect().not.toBeRegExp()', () => { 8 | expect(() => expect(new RegExp('i am a regular expression')).not.toBeRegExp()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeRegExp()', () => { 12 | expect(new RegExp('i am a regular expression')).toEqual(expect.toBeRegExp()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-same-length-as.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeSameLengthAs()', () => { 4 | expect(['i also have', '2 items']).toBeSameLengthAs(['i have', '2 items']); 5 | }); 6 | 7 | it('provides expect().not.toBeSameLengthAs()', () => { 8 | expect(() => 9 | expect(['i also have', '2 items']).not.toBeSameLengthAs(['i have', '2 items']), 10 | ).toThrow(); 11 | }); 12 | 13 | it('provides expect.toBeSameLengthAs()', () => { 14 | expect(['i also have', '2 items']).toEqual(expect.toBeSameLengthAs(['i have', '2 items'])); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-shorter-than.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeShorterThan()', () => { 4 | expect(['i have one item']).toBeShorterThan(['i', 'have', 4, 'items']); 5 | }); 6 | 7 | it('provides expect().not.toBeShorterThan()', () => { 8 | expect(() => 9 | expect(['i have one item']).not.toBeShorterThan(['i', 'have', 4, 'items']), 10 | ).toThrow(); 11 | }); 12 | 13 | it('provides expect.toBeShorterThan()', () => { 14 | expect(['i have one item']).toEqual(expect.toBeShorterThan(['i', 'have', 4, 'items'])); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeString()', () => { 4 | expect('i am a string').toBeString(); 5 | }); 6 | 7 | it('provides expect().not.toBeString()', () => { 8 | expect(() => expect('i am a string').not.toBeString()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeString()', () => { 12 | expect('i am a string').toEqual(expect.toBeString()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-true.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeTrue()', () => { 4 | expect(true).toBeTrue(); 5 | }); 6 | 7 | it('provides expect().not.toBeTrue()', () => { 8 | expect(() => expect(true).not.toBeTrue()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeTrue()', () => { 12 | expect(true).toEqual(expect.toBeTrue()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-valid-date.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeValidDate()', () => { 4 | expect(new Date('2020-01-01')).toBeValidDate(); 5 | }); 6 | 7 | it('provides expect().not.toBeValidDate()', () => { 8 | expect(() => expect(new Date('2020-01-01')).not.toBeValidDate()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeValidDate()', () => { 12 | expect(new Date('2020-01-01')).toEqual(expect.toBeValidDate()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-visible-string.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeVisibleString()', () => { 4 | expect('i am visible').toBeVisibleString(); 5 | }); 6 | 7 | it('provides expect().not.toBeVisibleString()', () => { 8 | expect(() => expect('i am visible').not.toBeVisibleString()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeVisibleString()', () => { 12 | expect('i am visible').toEqual(expect.toBeVisibleString()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-walkable.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeWalkable()', () => { 4 | expect({}).toBeWalkable(); 5 | }); 6 | 7 | it('provides expect().not.toBeWalkable()', () => { 8 | expect(() => expect({}).not.toBeWalkable()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeWalkable()', () => { 12 | expect({}).toEqual(expect.toBeWalkable()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-whitespace.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeWhitespace()', () => { 4 | expect(' ').toBeWhitespace(); 5 | }); 6 | 7 | it('provides expect().not.toBeWhitespace()', () => { 8 | expect(() => expect(' ').not.toBeWhitespace()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeWhitespace()', () => { 12 | expect(' ').toEqual(expect.toBeWhitespace()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-whole-number.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeWholeNumber()', () => { 4 | expect(8).toBeWholeNumber(); 5 | }); 6 | 7 | it('provides expect().not.toBeWholeNumber()', () => { 8 | expect(() => expect(8).not.toBeWholeNumber()).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeWholeNumber()', () => { 12 | expect(8).toEqual(expect.toBeWholeNumber()); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-be-within-range.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toBeWithinRange()', () => { 4 | expect(7).toBeWithinRange(0, 10); 5 | }); 6 | 7 | it('provides expect().not.toBeWithinRange()', () => { 8 | expect(() => expect(7).not.toBeWithinRange(0, 10)).toThrow(); 9 | }); 10 | 11 | it('provides expect.toBeWithinRange()', () => { 12 | expect(7).toEqual(expect.toBeWithinRange(0, 10)); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-end-with.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toEndWith()', () => { 4 | expect('JavaScript').toEndWith('Script'); 5 | }); 6 | 7 | it('provides expect().not.toEndWith()', () => { 8 | expect(() => expect('JavaScript').not.toEndWith('Script')).toThrow(); 9 | }); 10 | 11 | it('provides expect.toEndWith()', () => { 12 | expect('JavaScript').toEqual(expect.toEndWith('Script')); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/test/to-start-with.spec.ts: -------------------------------------------------------------------------------- 1 | import 'expect-more-jest'; 2 | 3 | it('provides expect().toStartWith()', () => { 4 | expect('JavaScript').toStartWith('Java'); 5 | }); 6 | 7 | it('provides expect().not.toStartWith()', () => { 8 | expect(() => expect('JavaScript').not.toStartWith('Java')).toThrow(); 9 | }); 10 | 11 | it('provides expect.toStartWith()', () => { 12 | expect('JavaScript').toEqual(expect.toStartWith('Java')); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/expect-more-jest/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "files": ["./src/index.ts"], 4 | "compilerOptions": { 5 | "esModuleInterop": true, 6 | "outDir": "./dist" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/expect-more/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "expect-more", 3 | "description": "Curried JavaScript Type Testing Library with Zero Dependencies", 4 | "version": "1.3.0", 5 | "author": "Jamie Mason (https://github.com/JamieMason)", 6 | "bugs": "https://github.com/JamieMason/expect-more/issues", 7 | "files": [ 8 | "dist" 9 | ], 10 | "homepage": "https://github.com/JamieMason/expect-more#readme", 11 | "keywords": [], 12 | "license": "MIT", 13 | "main": "dist/index.js", 14 | "repository": "JamieMason/expect-more", 15 | "scripts": { 16 | "prepublish": "cd ../../ && npm run build:expect-more" 17 | }, 18 | "sideEffects": false, 19 | "typings": "./dist/index.d.ts" 20 | } 21 | -------------------------------------------------------------------------------- /packages/expect-more/src/ends-with.ts: -------------------------------------------------------------------------------- 1 | import { isNonEmptyString } from './is-non-empty-string'; 2 | import { curry2 } from './lib/curry2'; 3 | 4 | /** 5 | * Asserts that value is a string whose trailing characters are equal to 6 | * those of the provided string. 7 | * @param otherString 'Script' 8 | * @param value 'JavaScript' 9 | * @matcherName toEndWith 10 | * @memberMatcherName toHaveEndingWith 11 | * @matcherMessage expected ${value} to end with ${otherString} 12 | * @matcherNotMessage expected ${value} not to end with ${otherString} 13 | */ 14 | export const endsWith = curry2( 15 | (otherString: unknown, value: unknown): value is string => 16 | isNonEmptyString(value) && 17 | isNonEmptyString(otherString) && 18 | value.slice(value.length - otherString.length, value.length) === otherString, 19 | ); 20 | -------------------------------------------------------------------------------- /packages/expect-more/src/gen/index.ts: -------------------------------------------------------------------------------- 1 | export { withMissingBranches } from './with-missing-branches'; 2 | export { withMissingLeaves } from './with-missing-leaves'; 3 | export { withMissingNodes } from './with-missing-nodes'; 4 | export { withNullBranches } from './with-null-branches'; 5 | export { withNullLeaves } from './with-null-leaves'; 6 | export { withNullNodes } from './with-null-nodes'; 7 | -------------------------------------------------------------------------------- /packages/expect-more/src/gen/with-missing-branches.ts: -------------------------------------------------------------------------------- 1 | import { createTreePermuter, removeNode } from './lib'; 2 | 3 | /** 4 | * Returns a `Generator` which emits every permutation of incomplete versions of 5 | * ${data} where a different `Object` or `Array` is `undefined` each time. 6 | */ 7 | export const withMissingBranches: (data: any) => Generator = createTreePermuter( 8 | (node, mutateNode) => { 9 | if (node.isBranch) { 10 | removeNode(node, mutateNode); 11 | } 12 | }, 13 | [undefined], 14 | ); 15 | -------------------------------------------------------------------------------- /packages/expect-more/src/gen/with-missing-leaves.ts: -------------------------------------------------------------------------------- 1 | import { createTreePermuter, removeNode } from './lib'; 2 | 3 | /** 4 | * Returns a `Generator` which emits every permutation of incomplete versions of 5 | * ${data} where a different primitive value is removed each time. 6 | */ 7 | export const withMissingLeaves: (data: any) => Generator = createTreePermuter( 8 | (node, mutateNode) => { 9 | if (node.isLeaf) { 10 | removeNode(node, mutateNode); 11 | } 12 | }, 13 | [undefined], 14 | ); 15 | -------------------------------------------------------------------------------- /packages/expect-more/src/gen/with-missing-nodes.ts: -------------------------------------------------------------------------------- 1 | import { createTreePermuter, removeNode } from './lib'; 2 | 3 | /** 4 | * Returns a `Generator` which emits every permutation of incomplete versions of 5 | * ${data} where one of every nested value is removed each time. 6 | */ 7 | export const withMissingNodes: (data: any) => Generator = createTreePermuter( 8 | removeNode, 9 | [undefined], 10 | ); 11 | -------------------------------------------------------------------------------- /packages/expect-more/src/gen/with-null-branches.ts: -------------------------------------------------------------------------------- 1 | import { createTreePermuter, nullifyNode } from './lib'; 2 | 3 | /** 4 | * Returns a `Generator` which emits every permutation of incomplete versions of 5 | * ${data} where a different `Object` or `Array` is replaced with `null` each 6 | * time. 7 | */ 8 | export const withNullBranches: (data: any) => Generator = createTreePermuter( 9 | (node, mutateNode) => { 10 | if (node.isBranch) { 11 | nullifyNode(node, mutateNode); 12 | } 13 | }, 14 | [null], 15 | ); 16 | -------------------------------------------------------------------------------- /packages/expect-more/src/gen/with-null-leaves.ts: -------------------------------------------------------------------------------- 1 | import { createTreePermuter, nullifyNode } from './lib'; 2 | 3 | /** 4 | * Returns a `Generator` which emits every permutation of incomplete versions of 5 | * ${data} where a different primitive value is replaced with `null` each time. 6 | */ 7 | export const withNullLeaves: (data: any) => Generator = createTreePermuter( 8 | (node, mutateNode) => { 9 | if (node.isLeaf) { 10 | nullifyNode(node, mutateNode); 11 | } 12 | }, 13 | [null], 14 | ); 15 | -------------------------------------------------------------------------------- /packages/expect-more/src/gen/with-null-nodes.ts: -------------------------------------------------------------------------------- 1 | import { createTreePermuter, nullifyNode } from './lib'; 2 | 3 | /** 4 | * Returns a `Generator` which emits every permutation of incomplete versions of 5 | * ${data} where one of every nested value is replaced with `null` each time. 6 | */ 7 | export const withNullNodes: (data: any) => Generator = createTreePermuter( 8 | nullifyNode, 9 | [null], 10 | ); 11 | -------------------------------------------------------------------------------- /packages/expect-more/src/has-member.ts: -------------------------------------------------------------------------------- 1 | import { isString } from './is-string'; 2 | import { isWalkable } from './is-walkable'; 3 | import { curry2 } from './lib/curry2'; 4 | 5 | /** 6 | * Asserts that a value has a property of the given name, even if the value of 7 | * that property is `undefined`. This assertion describes the shape of the given 8 | * value. For example, value.prop is `undefined` in both of the following 9 | * scenarios, but `{ prop: undefined }` and `{ }` do not have the same shape. 10 | * @param ownKeyName 'name' 11 | * @param value {} { name: 'Guybrush Threepwood' } 12 | * @matcherName toHaveMember 13 | * @memberMatcherName toHaveNestedMember 14 | * @matcherMessage expected ${value} to have a property at ${ownKeyName} 15 | * @matcherNotMessage expected ${value} not to have a property at ${ownKeyName} 16 | */ 17 | export const hasMember = curry2( 18 | (ownKeyName: string, value: unknown): value is any => 19 | isString(ownKeyName) && isWalkable(value) && ownKeyName in value, 20 | ); 21 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-after.ts: -------------------------------------------------------------------------------- 1 | import { isDate } from './is-date'; 2 | import { curry2 } from './lib/curry2'; 3 | 4 | /** 5 | * Asserts that a value is a valid instance of `Date` whose value occurs after 6 | * that of another. 7 | * @param otherDate new Date('2019-12-31') 8 | * @param value new Date('2020-01-01') 9 | * @matcherName toBeAfter 10 | * @memberMatcherName toHaveDateAfter 11 | * @matcherMessage expected ${value} to be an instance of Date, occurring after 12 | * ${otherDate} 13 | * @matcherNotMessage expected ${value} not to be an instance of Date, occurring 14 | * after ${otherDate} 15 | */ 16 | export const isAfter = curry2( 17 | (otherDate: Date, value: unknown): value is Date => 18 | isDate(value) && isDate(otherDate) && value.getTime() > otherDate.getTime(), 19 | ); 20 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-array-including-any-of.ts: -------------------------------------------------------------------------------- 1 | import { isArray } from './is-array'; 2 | import { curry2 } from './lib/curry2'; 3 | import { isJestEqual } from './lib/is-jest-equal'; 4 | import { some } from './lib/some'; 5 | 6 | /** 7 | * Asserts that `value` is an `Array` including at least one of the members of 8 | * `allowedValues`. 9 | * @param allowedValues ['Ginola', 3] 10 | * @param value [12, 0, 14, 'Ginola'] 11 | * @matcherName toBeArrayIncludingAnyOf 12 | * @memberMatcherName toHaveArrayIncludingAnyOf 13 | * @matcherMessage expected ${value} to include at least one of the values in 14 | * ${allowedValues} 15 | * @matcherNotMessage expected ${value} not to include at least one of the 16 | * values in ${allowedValues} 17 | */ 18 | export const isArrayIncludingAnyOf = curry2( 19 | (allowedValues: unknown[], value: unknown): value is any[] => 20 | isArray(allowedValues) && 21 | isArray(value) && 22 | some((allowedValue: unknown) => some(isJestEqual(allowedValue), value), allowedValues), 23 | ); 24 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-array-of-booleans.ts: -------------------------------------------------------------------------------- 1 | import { isArray } from './is-array'; 2 | import { isBoolean } from './is-boolean'; 3 | import { every } from './lib/every'; 4 | 5 | /** 6 | * Asserts that a value is an `Array` containing only `Boolean` values. 7 | * @param value [true, false, new Boolean(true)] 8 | * @matcherName toBeArrayOfBooleans 9 | * @memberMatcherName toHaveArrayOfBooleans 10 | * @matcherMessage expected ${value} to be a non-empty array, containing only 11 | * boolean values 12 | * @matcherNotMessage expected ${value} not to be a non-empty array, containing 13 | * only boolean values 14 | */ 15 | export const isArrayOfBooleans = (value: unknown): value is boolean[] => 16 | isArray(value) && every(isBoolean, value); 17 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-array-of-numbers.ts: -------------------------------------------------------------------------------- 1 | import { isArray } from './is-array'; 2 | import { isNumber } from './is-number'; 3 | import { every } from './lib/every'; 4 | 5 | /** 6 | * Asserts that a value is an `Array` containing only `Number` values. 7 | * @param value [12, 0, 14] 8 | * @matcherName toBeArrayOfNumbers 9 | * @memberMatcherName toHaveArrayOfNumbers 10 | * @matcherMessage expected ${value} to be a non-empty array, containing only 11 | * numbers 12 | * @matcherNotMessage expected ${value} not to be a non-empty array, containing 13 | * only numbers 14 | */ 15 | export const isArrayOfNumbers = (value: unknown): value is number[] => 16 | isArray(value) && every(isNumber, value); 17 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-array-of-objects.ts: -------------------------------------------------------------------------------- 1 | import { isArray } from './is-array'; 2 | import { isObject } from './is-object'; 3 | import { every } from './lib/every'; 4 | 5 | /** 6 | * Asserts that a value is an `Array` containing only `Object` values. 7 | * @param value [{}, new Object()] 8 | * @matcherName toBeArrayOfObjects 9 | * @memberMatcherName toHaveArrayOfObjects 10 | * @matcherMessage expected ${value} to be a non-empty array, containing only 11 | * objects 12 | * @matcherNotMessage expected ${value} not to be a non-empty array, containing 13 | * only objects 14 | */ 15 | export const isArrayOfObjects = (value: unknown): value is T => 16 | isArray(value) && every(isObject, value); 17 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-array-of-size.ts: -------------------------------------------------------------------------------- 1 | import { isArray } from './is-array'; 2 | import { isNumber } from './is-number'; 3 | import { curry2 } from './lib/curry2'; 4 | 5 | /** 6 | * Asserts that a value is an `Array` containing a specific number of values. 7 | * @param size 4 8 | * @param value ['i', 'contain', 4, 'items'] 9 | * @matcherName toBeArrayOfSize 10 | * @memberMatcherName toHaveArrayOfSize 11 | * @matcherMessage expected ${value} to be an array containing exactly ${size} 12 | * items 13 | * @matcherNotMessage expected ${value} not to be an array containing exactly 14 | * ${size} items 15 | */ 16 | export const isArrayOfSize = curry2( 17 | (size: number, value: unknown): value is any[] => 18 | isArray(value) && isNumber(size) && value.length === size, 19 | ); 20 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-array-of-strings.ts: -------------------------------------------------------------------------------- 1 | import { isArray } from './is-array'; 2 | import { isString } from './is-string'; 3 | import { every } from './lib/every'; 4 | 5 | /** 6 | * Asserts that a value is an `Array` containing only `String` values. 7 | * @param value ['we', 'are', 'all', 'strings'] 8 | * @matcherName toBeArrayOfStrings 9 | * @memberMatcherName toHaveArrayOfStrings 10 | * @matcherMessage expected ${value} to be a non-empty array, containing only 11 | * strings 12 | * @matcherNotMessage expected ${value} not to be a non-empty array, containing 13 | * only strings 14 | */ 15 | export const isArrayOfStrings = (value: unknown): value is string[] => 16 | isArray(value) && every(isString, value); 17 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-array.ts: -------------------------------------------------------------------------------- 1 | import { hasType } from './lib/has-type'; 2 | 3 | /** 4 | * Asserts that a value is a valid `Array` containing none or any number of 5 | * items of any type. 6 | * @param value [2, true, 'string'] 7 | * @matcherName toBeArray 8 | * @memberMatcherName toHaveArray 9 | * @matcherMessage expected ${value} to be an array 10 | * @matcherNotMessage expected ${value} not to be an array 11 | */ 12 | export const isArray = hasType('Array'); 13 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-async-function.ts: -------------------------------------------------------------------------------- 1 | import { hasType } from './lib/has-type'; 2 | 3 | /** 4 | * Asserts that a value is a function using `async` and `await` syntax. 5 | * @param value async () => { await fetch('...') } 6 | * @matcherName toBeAsyncFunction 7 | * @memberMatcherName toHaveAsyncFunction 8 | * @matcherMessage expected ${value} to be a `Function` using async/await syntax 9 | * @matcherNotMessage expected ${value} not to be a function using async/await 10 | * syntax 11 | */ 12 | export const isAsyncFunction = hasType<(...args: any[]) => Promise>('AsyncFunction'); 13 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-before.ts: -------------------------------------------------------------------------------- 1 | import { isAfter } from './is-after'; 2 | import { curry2 } from './lib/curry2'; 3 | 4 | /** 5 | * Asserts that a value is a valid instance of `Date` whose value occurs before 6 | * that of another. 7 | * @param other new Date('2020-01-01') 8 | * @param value new Date('2019-12-31') 9 | * @matcherName toBeBefore 10 | * @memberMatcherName toHaveDateBefore 11 | * @matcherMessage expected ${value} to be an instance of Date, occurring before 12 | * ${other} 13 | * @matcherNotMessage expected ${value} not to be an instance of Date, occurring 14 | * before ${other} 15 | */ 16 | export const isBefore = curry2((other: Date, value: unknown): value is Date => 17 | isAfter(value, other), 18 | ); 19 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-boolean.ts: -------------------------------------------------------------------------------- 1 | import { hasType } from './lib/has-type'; 2 | 3 | /** 4 | * Asserts that a value is `true`, `false`, `new Boolean(true)`, or `new 5 | * Boolean(false)`. 6 | * @param value false 7 | * @matcherName toBeBoolean 8 | * @memberMatcherName toHaveBoolean 9 | * @matcherMessage expected ${value} to be true, false, or an instance of 10 | * Boolean 11 | * @matcherNotMessage expected ${value} not to be true, false, or an instance of 12 | * Boolean 13 | */ 14 | export const isBoolean = hasType('Boolean'); 15 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-calculable.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Assert value can be used in Mathemetic calculations despite not being a 3 | * `Number`, for example `'1' * '2' === 2` whereas `'wut?' * 2 === NaN`. 4 | * @param value '100' 5 | * @matcherName toBeCalculable 6 | * @memberMatcherName toHaveCalculable 7 | * @matcherMessage expected ${value} to be coercible for use in mathemetical 8 | * operations 9 | * @matcherNotMessage expected ${value} not to be coercible for use in 10 | * mathemetical operations 11 | */ 12 | export const isCalculable = (value: any): value is T => !isNaN(value * 2); 13 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-date-in-month.ts: -------------------------------------------------------------------------------- 1 | import { isDate } from './is-date'; 2 | import { isNumber } from './is-number'; 3 | import { curry2 } from './lib/curry2'; 4 | 5 | /** 6 | * Asserts that a value is an instance of `Date` occurring on the given month of 7 | * the year, where January is `0` and December is `11`. 8 | * @param index 7 9 | * @param value new Date('2021-08-29') 10 | * @matcherName toBeDateInMonth 11 | * @memberMatcherName toHaveDateInMonth 12 | * @matcherMessage expected ${value} to be an instance of Date occurring on the 13 | * month of the year with index ${index} 14 | * @matcherNotMessage expected ${value} not to be an instance of Date occurring 15 | * on the month of the year with index ${index} 16 | */ 17 | export const isDateInMonth = curry2( 18 | (index: number, value: unknown): value is Date => 19 | isDate(value) && isNumber(index) && value.getMonth() === index, 20 | ); 21 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-date-in-year.ts: -------------------------------------------------------------------------------- 1 | import { isDate } from './is-date'; 2 | import { isNumber } from './is-number'; 3 | import { curry2 } from './lib/curry2'; 4 | 5 | /** 6 | * Asserts that a value is an instance of `Date` occurring in the given year. 7 | * @param year 2021 8 | * @param value new Date('2021-08-29') 9 | * @matcherName toBeDateInYear 10 | * @memberMatcherName toHaveDateInYear 11 | * @matcherMessage expected ${value} to be an instance of Date occurring in the 12 | * year ${year} 13 | * @matcherNotMessage expected ${value} not to be an instance of Date occurring 14 | * in the year ${year} 15 | */ 16 | export const isDateInYear = curry2( 17 | (year: number, value: unknown): value is Date => 18 | isDate(value) && isNumber(year) && value.getFullYear() === year, 19 | ); 20 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-date-on-day-of-month.ts: -------------------------------------------------------------------------------- 1 | import { isDate } from './is-date'; 2 | import { isNumber } from './is-number'; 3 | import { curry2 } from './lib/curry2'; 4 | 5 | /** 6 | * Asserts that a value is an instance of `Date` occurring on the given day of 7 | * the month, where the first day of the month is `1` and last is `31`. 8 | * @param dayOfMonth 29 9 | * @param value new Date('2021-08-29') 10 | * @matcherName toBeDateOnDayOfMonth 11 | * @memberMatcherName toHaveDateOnDayOfMonth 12 | * @matcherMessage expected ${value} to be an instance of Date occurring on the 13 | * ${dayOfMonth} day of the month 14 | * @matcherNotMessage expected ${value} not to be an instance of Date occurring 15 | * on the ${dayOfMonth} day of the month 16 | */ 17 | export const isDateOnDayOfMonth = curry2( 18 | (dayOfMonth: number, value: unknown): value is Date => 19 | isDate(value) && isNumber(dayOfMonth) && value.getDate() === dayOfMonth, 20 | ); 21 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-date-on-day-of-week.ts: -------------------------------------------------------------------------------- 1 | import { isDate } from './is-date'; 2 | import { isNumber } from './is-number'; 3 | import { curry2 } from './lib/curry2'; 4 | 5 | /** 6 | * Asserts that a value is an instance of `Date` occurring on the day of the 7 | * week with the given index, where Sunday is `0` and Saturday is `6`. 8 | * @param index 0 9 | * @param value new Date('2021-08-29') 10 | * @matcherName toBeDateOnDayOfWeek 11 | * @memberMatcherName toHaveDateOnDayOfWeek 12 | * @matcherMessage expected ${value} to be an instance of Date occurring on the 13 | * day of the week with index ${index} 14 | * @matcherNotMessage expected ${value} not to be an instance of Date occurring 15 | * on the day of the week with index ${index} 16 | */ 17 | export const isDateOnDayOfWeek = curry2( 18 | (index: number, value: unknown): value is Date => 19 | isDate(value) && isNumber(index) && value.getDay() === index, 20 | ); 21 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-date-on-or-after.ts: -------------------------------------------------------------------------------- 1 | import { isDate } from './is-date'; 2 | import { isGreaterThanOrEqualTo } from './is-greater-than-or-equal-to'; 3 | import { curry2 } from './lib/curry2'; 4 | 5 | /** 6 | * Asserts that a value is an instance of `Date` occurring on or after the exact 7 | * date and time of another. 8 | * @param other new Date('2019-12-15') 9 | * @param value new Date('2019-12-31') 10 | * @matcherName toBeDateOnOrAfter 11 | * @memberMatcherName toHaveDateOnOrAfter 12 | * @matcherMessage expected ${value} to be an instance of Date occurring on or 13 | * after ${other} 14 | * @matcherNotMessage expected ${value} not to be an instance of Date occurring 15 | * on or after ${other} 16 | */ 17 | export const isDateOnOrAfter = curry2( 18 | (other: unknown, value: unknown): value is Date => 19 | isDate(value) && isDate(other) && isGreaterThanOrEqualTo(other.getTime(), value.getTime()), 20 | ); 21 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-date-on-or-before.ts: -------------------------------------------------------------------------------- 1 | import { isDate } from './is-date'; 2 | import { isLessThanOrEqualTo } from './is-less-than-or-equal-to'; 3 | import { curry2 } from './lib/curry2'; 4 | 5 | /** 6 | * Asserts that a value is an instance of `Date` occurring on or before the exact 7 | * date and time of another. 8 | * @param other new Date('2019-12-31') 9 | * @param value new Date('2019-12-15') 10 | * @matcherName toBeDateOnOrBefore 11 | * @memberMatcherName toHaveDateOnOrBefore 12 | * @matcherMessage expected ${value} to be an instance of Date occurring on or 13 | * before ${other} 14 | * @matcherNotMessage expected ${value} not to be an instance of Date occurring 15 | * on or before ${other} 16 | */ 17 | export const isDateOnOrBefore = curry2( 18 | (other: unknown, value: unknown): value is Date => 19 | isDate(value) && isDate(other) && isLessThanOrEqualTo(other.getTime(), value.getTime()), 20 | ); 21 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-date.ts: -------------------------------------------------------------------------------- 1 | import { hasType } from './lib/has-type'; 2 | 3 | /** 4 | * Asserts that a value is an instance of `Date`. 5 | * @param value new Date('2019-12-31') 6 | * @matcherName toBeDate 7 | * @memberMatcherName toHaveDate 8 | * @matcherMessage expected ${value} to be an instance of Date 9 | * @matcherNotMessage expected ${value} not to be an instance of Date 10 | */ 11 | export const isDate = hasType('Date'); 12 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-decimal-number.ts: -------------------------------------------------------------------------------- 1 | import { isNumber } from './is-number'; 2 | 3 | /** 4 | * Asserts that a value is a `Number` with positive decimal places. 5 | * @param value 12.55 6 | * @matcherName toBeDecimalNumber 7 | * @memberMatcherName toHaveDecimalNumber 8 | * @matcherMessage expected ${value} to be a number with positive decimal places 9 | * @matcherNotMessage expected ${value} not to be a number with positive decimal 10 | * places 11 | */ 12 | export const isDecimalNumber = (value: unknown): value is number => 13 | isNumber(value) && String(value).indexOf('.') !== -1; 14 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-divisible-by.ts: -------------------------------------------------------------------------------- 1 | import { isNumber } from './is-number'; 2 | import { curry2 } from './lib/curry2'; 3 | 4 | /** 5 | * Asserts that a value is a `Number` which results in a whole number when 6 | * divided by another. 7 | * @param other 2 8 | * @param value 12 9 | * @matcherName toBeDivisibleBy 10 | * @memberMatcherName toHaveDivisibleBy 11 | * @matcherMessage expected ${value} to be divisible by ${other} 12 | * @matcherNotMessage expected ${value} not to be divisible by ${other} 13 | */ 14 | export const isDivisibleBy = curry2( 15 | (other: number, value: unknown): value is number => 16 | isNumber(value) && isNumber(other) && value % other === 0, 17 | ); 18 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-empty-array.ts: -------------------------------------------------------------------------------- 1 | import { isArrayOfSize } from './is-array-of-size'; 2 | 3 | /** 4 | * Asserts that a value is a valid `Array` containing no items. 5 | * @param value [] 6 | * @matcherName toBeEmptyArray 7 | * @memberMatcherName toHaveEmptyArray 8 | * @matcherMessage expected ${value} to be an array containing no items 9 | * @matcherNotMessage expected ${value} not to be an array containing no items 10 | */ 11 | export const isEmptyArray = (value: unknown): value is T => 12 | isArrayOfSize(0, value); 13 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-empty-object.ts: -------------------------------------------------------------------------------- 1 | import { isObject } from './is-object'; 2 | import { keys } from './lib/keys'; 3 | 4 | /** 5 | * Asserts that a value is a valid `Object` containing no instance members. 6 | * @param value {} {} 7 | * @matcherName toBeEmptyObject 8 | * @memberMatcherName toHaveEmptyObject 9 | * @matcherMessage expected ${value} to be an empty object 10 | * @matcherNotMessage expected ${value} not to be an empty object 11 | */ 12 | export const isEmptyObject = >(value: unknown): value is T => 13 | isObject(value) && keys(value).length === 0; 14 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-empty-string.ts: -------------------------------------------------------------------------------- 1 | import { isString } from './is-string'; 2 | 3 | /** 4 | * Asserts that a value is a valid `String` containing no characters. 5 | * @param value '' 6 | * @matcherName toBeEmptyString 7 | * @memberMatcherName toHaveEmptyString 8 | * @matcherMessage expected ${value} to be an empty string or empty instance of 9 | * String 10 | * @matcherNotMessage expected ${value} not to be an empty string or empty 11 | * instance of String 12 | */ 13 | export const isEmptyString = (value: unknown): value is '' => isString(value) && value.length === 0; 14 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-even-number.ts: -------------------------------------------------------------------------------- 1 | import { isDivisibleBy } from './is-divisible-by'; 2 | import { isNumber } from './is-number'; 3 | 4 | /** 5 | * Asserts that a value is an even `Number`. 6 | * @param value 2 7 | * @matcherName toBeEvenNumber 8 | * @memberMatcherName toHaveEvenNumber 9 | * @matcherMessage expected ${value} to be an even number 10 | * @matcherNotMessage expected ${value} not to be an even number 11 | */ 12 | export const isEvenNumber = (value: unknown): value is number => 13 | isNumber(value) && isDivisibleBy(2, value); 14 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-false.ts: -------------------------------------------------------------------------------- 1 | import { isBoolean } from './is-boolean'; 2 | 3 | /** 4 | * Asserts that a value is `false` or `new Boolean(false)`. 5 | * @param value false 6 | * @matcherName toBeFalse 7 | * @memberMatcherName toHaveFalse 8 | * @matcherMessage expected ${value} to be false or Boolean(false) 9 | * @matcherNotMessage expected ${value} not to be false or Boolean(false) 10 | */ 11 | export const isFalse = (value: unknown): value is false => 12 | value === false || (isBoolean(value) && value.valueOf() === false); 13 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-function.ts: -------------------------------------------------------------------------------- 1 | import { AnyFn } from './typings'; 2 | 3 | /** 4 | * Asserts that a value is a `Function`. 5 | * @param value () => 'i am a function' 6 | * @matcherName toBeFunction 7 | * @memberMatcherName toHaveMethod 8 | * @matcherMessage expected ${value} to be a function or async function 9 | * @matcherNotMessage expected ${value} not to be a function or async function 10 | */ 11 | export const isFunction = (value: unknown): value is T => 12 | typeof value === 'function'; 13 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-generator-function.ts: -------------------------------------------------------------------------------- 1 | import { hasType } from './lib/has-type'; 2 | 3 | /** 4 | * Asserts that a value is a `Function` using `yield` syntax. 5 | * @param value function* gen() { yield 'i am a generator' } 6 | * @matcherName toBeGeneratorFunction 7 | * @memberMatcherName toHaveGeneratorFunction 8 | * @matcherMessage expected ${value} to be a function using yield syntax. 9 | * @matcherNotMessage expected ${value} not to be a function using yield syntax. 10 | */ 11 | export const isGeneratorFunction = hasType('GeneratorFunction'); 12 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-greater-than-or-equal-to.ts: -------------------------------------------------------------------------------- 1 | import { isNumber } from './is-number'; 2 | import { curry2 } from './lib/curry2'; 3 | 4 | /** 5 | * Asserts that a value is greater than or equal to ${other}. 6 | * @param other 5 7 | * @param value 10 8 | * @matcherName toBeGreaterThanOrEqualTo 9 | * @memberMatcherName toHaveGreaterThanOrEqualTo 10 | * @matcherMessage expected ${value} to be greater than or equal to ${other} 11 | * @matcherNotMessage expected ${value} not to be greater than or equal to 12 | * ${other} 13 | */ 14 | export const isGreaterThanOrEqualTo = curry2( 15 | (other: number, value: unknown): value is number => 16 | isNumber(value) && isNumber(other) && value >= other, 17 | ); 18 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-json-string.ts: -------------------------------------------------------------------------------- 1 | import { isString } from './is-string'; 2 | 3 | /** 4 | * Asserts that a value is a `String` of valid JSON. 5 | * @param value '{"i":"am valid JSON"}' 6 | * @matcherName toBeJsonString 7 | * @memberMatcherName toHaveJsonString 8 | * @matcherMessage expected ${value} to be a string of valid JSON 9 | * @matcherNotMessage expected ${value} not to be a string of valid JSON 10 | */ 11 | export const isJsonString = (value: unknown): value is string => { 12 | try { 13 | return isString(value) && JSON.parse(value) !== null; 14 | } catch (err) { 15 | return false; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-less-than-or-equal-to.ts: -------------------------------------------------------------------------------- 1 | import { isNumber } from './is-number'; 2 | import { curry2 } from './lib/curry2'; 3 | 4 | /** 5 | * Asserts that a value is less than or equal to another. 6 | * @param other 12 7 | * @param value 8 8 | * @matcherName toBeLessThanOrEqualTo 9 | * @memberMatcherName toHaveLessThanOrEqualTo 10 | * @matcherMessage expected ${value} to be less than or equal to ${other} 11 | * @matcherNotMessage expected ${value} not to be less than or equal to ${other} 12 | */ 13 | export const isLessThanOrEqualTo = curry2( 14 | (other: number, value: unknown): value is number => 15 | isNumber(value) && isNumber(other) && value <= other, 16 | ); 17 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-longer-than.ts: -------------------------------------------------------------------------------- 1 | import { curry2 } from './lib/curry2'; 2 | import { isIndexedList } from './lib/is-indexed-list'; 3 | 4 | /** 5 | * Asserts that a value is a `String` or `Array` whose length is greater than 6 | * that of another. 7 | * @param other [2, 'items'] 8 | * @param value ['i', 'have', 3] 9 | * @matcherName toBeLongerThan 10 | * @memberMatcherName toHaveLongerThan 11 | * @matcherMessage expected ${value} to be a string or array whose length is 12 | * greater than that of ${other} 13 | * @matcherNotMessage expected ${value} not to be a string or array whose length 14 | * is greater than that of ${other} 15 | */ 16 | export const isLongerThan = curry2( 17 | (other: string | any[], value: unknown): value is string | any[] => 18 | isIndexedList(value) && isIndexedList(other) && value.length > other.length, 19 | ); 20 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-near.ts: -------------------------------------------------------------------------------- 1 | import { isWithinRange } from './is-within-range'; 2 | import { curry3 } from './lib/curry3'; 3 | 4 | /** 5 | * Asserts that a value is a number within the given acceptable distance from 6 | * another. 7 | * @param otherNumber 5 8 | * @param epsilon 0.5 9 | * @param value 4.8 10 | * @matcherName toBeNear 11 | * @memberMatcherName toHaveNumberNear 12 | * @matcherMessage expected ${value} to be within ${epsilon} greater or less 13 | * than ${otherNumber} 14 | * @matcherNotMessage expected ${value} not to be within ${epsilon} greater or 15 | * less than ${otherNumber} 16 | */ 17 | export const isNear = curry3((otherNumber: number, epsilon: number, value: any): value is number => 18 | isWithinRange(otherNumber - epsilon, otherNumber + epsilon, value), 19 | ); 20 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-negative-number.ts: -------------------------------------------------------------------------------- 1 | import { isNumber } from './is-number'; 2 | 3 | /** 4 | * Asserts that a value is a `Number` less than 0. 5 | * @param value -18 6 | * @matcherName toBeNegativeNumber 7 | * @memberMatcherName toHaveNegativeNumber 8 | * @matcherMessage expected ${value} to be a negative number 9 | * @matcherNotMessage expected ${value} not to be a negative number 10 | */ 11 | export const isNegativeNumber = (value: unknown): value is number => isNumber(value) && value < 0; 12 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-nil.ts: -------------------------------------------------------------------------------- 1 | import { isNull } from './is-null'; 2 | import { isUndefined } from './is-undefined'; 3 | 4 | /** 5 | * Asserts that a value is `null` or `undefined` 6 | * @param value undefined 7 | * @matcherName toBeNil 8 | * @memberMatcherName toHaveNil 9 | * @matcherMessage expected ${value} to be null or undefined 10 | * @matcherNotMessage expected ${value} not to be null or undefined 11 | */ 12 | export const isNil = (value: unknown): value is undefined | null => 13 | isNull(value) || isUndefined(value); 14 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-non-empty-array.ts: -------------------------------------------------------------------------------- 1 | import { isArray } from './is-array'; 2 | 3 | /** 4 | * Asserts that a value is an `Array` containing at least one value. 5 | * @param value ['i', 'am not empty'] 6 | * @matcherName toBeNonEmptyArray 7 | * @memberMatcherName toHaveNonEmptyArray 8 | * @matcherMessage expected ${value} to be an array with at least one item 9 | * @matcherNotMessage expected ${value} not to be an array with at least one 10 | * item 11 | */ 12 | export const isNonEmptyArray = (value: unknown): value is T => 13 | isArray(value) && value.length > 0; 14 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-non-empty-object.ts: -------------------------------------------------------------------------------- 1 | import { isObject } from './is-object'; 2 | import { keys } from './lib/keys'; 3 | 4 | /** 5 | * Asserts that a value is an `Object` containing at least one own member. 6 | * @param value {} { i: 'am not empty' } 7 | * @matcherName toBeNonEmptyObject 8 | * @memberMatcherName toHaveNonEmptyObject 9 | * @matcherMessage expected ${value} to be an object with at least one own 10 | * member 11 | * @matcherNotMessage expected ${value} not to be an object with at least one 12 | * own member 13 | */ 14 | export const isNonEmptyObject = (value: unknown): value is T => 15 | isObject(value) && keys(value).length > 0; 16 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-non-empty-string.ts: -------------------------------------------------------------------------------- 1 | import { isString } from './is-string'; 2 | 3 | /** 4 | * Asserts that a value is a valid `String` containing at least one character. 5 | * @param value 'i am not empty' 6 | * @matcherName toBeNonEmptyString 7 | * @memberMatcherName toHaveNonEmptyString 8 | * @matcherMessage expected ${value} to be a string with at least one character 9 | * @matcherNotMessage expected ${value} not to be a string with at least one 10 | * character 11 | */ 12 | export const isNonEmptyString = (value: unknown): value is string => 13 | isString(value) && value.length > 0; 14 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-null.ts: -------------------------------------------------------------------------------- 1 | import { hasType } from './lib/has-type'; 2 | 3 | /** 4 | * Asserts that a value is `null`. 5 | * @param value null 6 | * @matcherName toBeNull 7 | * @memberMatcherName toHaveNull 8 | * @matcherMessage expected ${value} to be null 9 | * @matcherNotMessage expected ${value} not to be null 10 | */ 11 | export const isNull = hasType('Null'); 12 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-number.ts: -------------------------------------------------------------------------------- 1 | import { hasType } from './lib/has-type'; 2 | 3 | /** 4 | * Asserts that a value is a valid `Number` or `new Number()` and not `NaN`. 5 | * @param value 8 6 | * @matcherName toBeNumber 7 | * @memberMatcherName toHaveNumber 8 | * @matcherMessage expected ${value} to be a valid number 9 | * @matcherNotMessage expected ${value} not to be a valid number 10 | */ 11 | export const isNumber = (value: unknown): value is number => 12 | hasType('Number')(value) && !isNaN(parseFloat(String(value))); 13 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-object.ts: -------------------------------------------------------------------------------- 1 | import { hasType } from './lib/has-type'; 2 | 3 | /** 4 | * Asserts that a value is an `Object`. 5 | * @param value {} {} 6 | * @matcherName toBeObject 7 | * @memberMatcherName toHaveObject 8 | * @matcherMessage expected ${value} to be an object 9 | * @matcherNotMessage expected ${value} not to be an object 10 | */ 11 | export const isObject = hasType('Object'); 12 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-odd-number.ts: -------------------------------------------------------------------------------- 1 | import { isDivisibleBy } from './is-divisible-by'; 2 | import { isNumber } from './is-number'; 3 | 4 | /** 5 | * Asserts that a value is an odd `Number`. 6 | * @param value 5 7 | * @matcherName toBeOddNumber 8 | * @memberMatcherName toHaveOddNumber 9 | * @matcherMessage expected ${value} to be an odd number 10 | * @matcherNotMessage expected ${value} not to be an odd number 11 | */ 12 | export const isOddNumber = (value: unknown): value is number => 13 | isNumber(value) && !isDivisibleBy(2, value); 14 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-positive-number.ts: -------------------------------------------------------------------------------- 1 | import { isNumber } from './is-number'; 2 | 3 | /** 4 | * Asserts that a value is a `Number` greater than 0. 5 | * @param value 5 6 | * @matcherName toBePositiveNumber 7 | * @memberMatcherName toHavePositiveNumber 8 | * @matcherMessage expected ${value} to be a positive number 9 | * @matcherNotMessage expected ${value} not to be a positive number 10 | */ 11 | export const isPositiveNumber = (value: unknown): value is number => isNumber(value) && value > 0; 12 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-reg-exp.ts: -------------------------------------------------------------------------------- 1 | import { hasType } from './lib/has-type'; 2 | 3 | /** 4 | * Asserts that a value is a `RegExp`. 5 | * @param value new RegExp('i am a regular expression') 6 | * @matcherName toBeRegExp 7 | * @memberMatcherName toHaveRegExp 8 | * @matcherMessage expected ${value} to be a regular expression 9 | * @matcherNotMessage expected ${value} not to be a regular expression 10 | */ 11 | export const isRegExp = hasType('RegExp'); 12 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-same-length-as.ts: -------------------------------------------------------------------------------- 1 | import { curry2 } from './lib/curry2'; 2 | import { isIndexedList } from './lib/is-indexed-list'; 3 | 4 | /** 5 | * Asserts that a value is a `String` or `Array` whose length is the same as 6 | * that of the other provided. 7 | * @param other ['i have', '2 items'] 8 | * @param value ['i also have', '2 items'] 9 | * @matcherName toBeSameLengthAs 10 | * @memberMatcherName toHaveSameLengthAs 11 | * @matcherMessage expected ${value} to be a string or array whose length is the 12 | * same as that of ${other} 13 | * @matcherNotMessage expected ${value} not to be a string or array whose length 14 | * is the same as that of ${other} 15 | */ 16 | export const isSameLengthAs = curry2( 17 | (other: string | any[], value: unknown): value is string | any[] => 18 | isIndexedList(value) && isIndexedList(other) && value.length === other.length, 19 | ); 20 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-shorter-than.ts: -------------------------------------------------------------------------------- 1 | import { curry2 } from './lib/curry2'; 2 | import { isIndexedList } from './lib/is-indexed-list'; 3 | 4 | /** 5 | * Asserts that a value is a `String` or `Array` whose length is less than that 6 | * of the other provided. 7 | * @param other ['i', 'have', 4, 'items'] 8 | * @param value ['i have one item'] 9 | * @matcherName toBeShorterThan 10 | * @memberMatcherName toHaveShorterThan 11 | * @matcherMessage expected ${value} to be a string or array whose length is 12 | * less than that of ${other} 13 | * @matcherNotMessage expected ${value} not to be a string or array whose length 14 | * is less than that of ${other} 15 | */ 16 | export const isShorterThan = curry2( 17 | (other: string | any[], value: unknown): value is string | any[] => 18 | isIndexedList(value) && isIndexedList(other) && value.length < other.length, 19 | ); 20 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-string.ts: -------------------------------------------------------------------------------- 1 | import { hasType } from './lib/has-type'; 2 | 3 | /** 4 | * Asserts that a value is a `String` or `new String()`. 5 | * @param value 'i am a string' 6 | * @matcherName toBeString 7 | * @memberMatcherName toHaveString 8 | * @matcherMessage expected ${value} to be a string 9 | * @matcherNotMessage expected ${value} not to be a string 10 | */ 11 | export const isString = hasType('String'); 12 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-true.ts: -------------------------------------------------------------------------------- 1 | import { isBoolean } from './is-boolean'; 2 | 3 | /** 4 | * Asserts that a value is `true` or `new Boolean(true)`. 5 | * @param value true 6 | * @matcherName toBeTrue 7 | * @memberMatcherName toHaveTrue 8 | * @matcherMessage expected ${value} to be true or Boolean(true) 9 | * @matcherNotMessage expected ${value} not to be true or Boolean(true) 10 | */ 11 | export const isTrue = (value: unknown): value is true => 12 | value === true || (isBoolean(value) && value.valueOf() === true); 13 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-undefined.ts: -------------------------------------------------------------------------------- 1 | import { hasType } from './lib/has-type'; 2 | 3 | /** 4 | * Asserts that a value is `undefined` 5 | * @param value undefined 6 | * @matcherName toBeUndefined 7 | * @memberMatcherName toHaveUndefined 8 | * @matcherMessage expected ${value} to be undefined 9 | * @matcherNotMessage expected ${value} not to be undefined 10 | */ 11 | export const isUndefined = hasType('Undefined'); 12 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-valid-date.ts: -------------------------------------------------------------------------------- 1 | import { isDate } from './is-date'; 2 | 3 | /** 4 | * Asserts that a value is an instance of `Date` whose internal value is valid. 5 | * `Date` is little like `Promise` in that it is a container for a value. For 6 | * example, `new Date('wut?')` is a valid `Date` which wraps a value that is not 7 | * valid. 8 | * @param value new Date('2020-01-01') 9 | * @matcherName toBeValidDate 10 | * @memberMatcherName toHaveValidDate 11 | * @matcherMessage expected ${value} to be an instance of Date with a valid 12 | * value 13 | * @matcherNotMessage expected ${value} not to be an instance of Date with a 14 | * valid value 15 | */ 16 | export const isValidDate = (value: unknown): value is Date => 17 | isDate(value) && !isNaN(value.getTime()); 18 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-visible-string.ts: -------------------------------------------------------------------------------- 1 | import { isString } from './is-string'; 2 | 3 | /** 4 | * Asserts that a value is a valid `String` containing at least one character 5 | * which is not whitespace. 6 | * @param value 'i am visible' 7 | * @matcherName toBeVisibleString 8 | * @memberMatcherName toHaveVisibleString 9 | * @matcherMessage expected ${value} to be a string with at least one 10 | * non-whitespace character 11 | * @matcherNotMessage expected ${value} not to be a string with at least one 12 | * non-whitespace character 13 | */ 14 | export const isVisibleString = (value: unknown): value is string => 15 | isString(value) && value.length > 0 && value.search(/\S/) !== -1; 16 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-walkable.ts: -------------------------------------------------------------------------------- 1 | import { isNull } from './is-null'; 2 | import { isUndefined } from './is-undefined'; 3 | 4 | /** 5 | * Asserts that a value is safe to attempt to read property values from. 6 | * @param value {} {} 7 | * @matcherName toBeWalkable 8 | * @memberMatcherName toHaveWalkable 9 | * @matcherMessage expected ${value} to be walkable 10 | * @matcherNotMessage expected ${value} not to be walkable 11 | */ 12 | export const isWalkable = (value: unknown): value is T => 13 | !isNull(value) && !isUndefined(value); 14 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-whitespace.ts: -------------------------------------------------------------------------------- 1 | import { isString } from './is-string'; 2 | 3 | /** 4 | * Asserts that a value is a `String` containing only whitespace characters. 5 | * @param value ' ' 6 | * @matcherName toBeWhitespace 7 | * @memberMatcherName toHaveWhitespace 8 | * @matcherMessage expected ${value} to be a string containing only whitespace 9 | * characters 10 | * @matcherNotMessage expected ${value} not to be a string containing only 11 | * whitespace characters 12 | */ 13 | export const isWhitespace = (value: unknown): value is string => 14 | isString(value) && value.search(/\S/) === -1; 15 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-whole-number.ts: -------------------------------------------------------------------------------- 1 | import { isDivisibleBy } from './is-divisible-by'; 2 | import { isNumber } from './is-number'; 3 | 4 | /** 5 | * Asserts that a value is a `Number` with no positive decimal places. 6 | * @param value 8 7 | * @matcherName toBeWholeNumber 8 | * @memberMatcherName toHaveWholeNumber 9 | * @matcherMessage expected ${value} to be a whole number 10 | * @matcherNotMessage expected ${value} not to be a whole number 11 | */ 12 | export const isWholeNumber = (value: unknown): value is number => 13 | isNumber(value) && (value === 0 || isDivisibleBy(1, value)); 14 | -------------------------------------------------------------------------------- /packages/expect-more/src/is-within-range.ts: -------------------------------------------------------------------------------- 1 | import { isGreaterThanOrEqualTo } from './is-greater-than-or-equal-to'; 2 | import { isLessThanOrEqualTo } from './is-less-than-or-equal-to'; 3 | import { curry3 } from './lib/curry3'; 4 | 5 | /** 6 | * Asserts that a value is a `Number` which is both greater than or equal to 7 | * `floor` and less than or equal to `ceiling`. 8 | * @param floor 0 9 | * @param ceiling 10 10 | * @param value 7 11 | * @matcherName toBeWithinRange 12 | * @memberMatcherName toHaveNumberWithinRange 13 | * @matcherMessage expected ${value} to be greater than or equal to ${floor} and 14 | * less than or equal to ${ceiling} 15 | * @matcherNotMessage expected ${value} not to be greater than or equal to 16 | * ${floor} and less than or equal to ${ceiling} 17 | */ 18 | export const isWithinRange = curry3( 19 | (floor: number, ceiling: number, value: unknown): value is number => 20 | isLessThanOrEqualTo(ceiling, value) && isGreaterThanOrEqualTo(floor, value), 21 | ); 22 | -------------------------------------------------------------------------------- /packages/expect-more/src/lib/curry1.ts: -------------------------------------------------------------------------------- 1 | type Fn1 = (a: unknown) => a is R; 2 | 3 | export type CurriedFn1 = { 4 | (a: unknown): a is R; 5 | }; 6 | 7 | export function curry1(fn: Fn1): CurriedFn1 { 8 | return function curriedFn1(a) { 9 | if (arguments.length >= 1) return fn(a); 10 | } as CurriedFn1; 11 | } 12 | -------------------------------------------------------------------------------- /packages/expect-more/src/lib/curry2.ts: -------------------------------------------------------------------------------- 1 | import { CurriedFn1, curry1 } from './curry1'; 2 | 3 | type Fn2 = (b: unknown, a: unknown) => a is R; 4 | 5 | export type CurriedFn2 = { 6 | (b: unknown, a: unknown): a is R; 7 | (b: unknown): CurriedFn1; 8 | }; 9 | 10 | export function curry2(fn: Fn2): CurriedFn2 { 11 | return function curriedFn2(b, a) { 12 | const len = arguments.length; 13 | if (len >= 2) return fn(b, a); 14 | if (len >= 1) return curry1(fn.bind(null, b)); 15 | } as CurriedFn2; 16 | } 17 | -------------------------------------------------------------------------------- /packages/expect-more/src/lib/curry3.ts: -------------------------------------------------------------------------------- 1 | import { CurriedFn1, curry1 } from './curry1'; 2 | import { CurriedFn2, curry2 } from './curry2'; 3 | 4 | type Fn3 = (c: unknown, b: unknown, a: unknown) => a is R; 5 | 6 | export type CurriedFn3 = { 7 | (c: unknown, b: unknown, a: unknown): a is R; 8 | (c: unknown, b: unknown): CurriedFn1; 9 | (c: unknown): CurriedFn2; 10 | }; 11 | 12 | export function curry3(fn: Fn3): CurriedFn3 { 13 | return function curriedFn3(c, b, a) { 14 | const len = arguments.length; 15 | if (len >= 3) return fn(c, b, a); 16 | if (len >= 2) return curry1(fn.bind(null, c, b)); 17 | if (len >= 1) return curry2(fn.bind(null, c)); 18 | } as CurriedFn3; 19 | } 20 | -------------------------------------------------------------------------------- /packages/expect-more/src/lib/every.ts: -------------------------------------------------------------------------------- 1 | import { UnaryBoolFn } from '../typings'; 2 | import { curry2 } from './curry2'; 3 | 4 | export const every = curry2((fn: UnaryBoolFn, array: any[]): array is any[] => { 5 | for (let i = 0, len = array.length; i < len; i++) { 6 | if (fn(array[i]) === false) { 7 | return false; 8 | } 9 | } 10 | return array.length > 0; 11 | }); 12 | -------------------------------------------------------------------------------- /packages/expect-more/src/lib/get-type.ts: -------------------------------------------------------------------------------- 1 | export const getType = (value: unknown): string => Object.prototype.toString.call(value); 2 | -------------------------------------------------------------------------------- /packages/expect-more/src/lib/has-type.ts: -------------------------------------------------------------------------------- 1 | import { getType } from './get-type'; 2 | 3 | export const hasType = 4 | (type: string) => 5 | (value: unknown): value is CallTimeType => 6 | getType(value) === `[object ${type}]`; 7 | -------------------------------------------------------------------------------- /packages/expect-more/src/lib/is-asym.ts: -------------------------------------------------------------------------------- 1 | import { isFunction } from '../is-function'; 2 | import { isObject } from '../is-object'; 3 | 4 | interface AsymmetricMatcher { 5 | asymmetricMatch(value: unknown): boolean; 6 | } 7 | 8 | export function isAsym(value: unknown): value is AsymmetricMatcher { 9 | return isObject(value) && isFunction(value.asymmetricMatch); 10 | } 11 | -------------------------------------------------------------------------------- /packages/expect-more/src/lib/is-indexed-list.ts: -------------------------------------------------------------------------------- 1 | import { isArray } from '../is-array'; 2 | import { isString } from '../is-string'; 3 | 4 | export const isIndexedList = (value: unknown): value is string | any[] => 5 | isString(value) || isArray(value); 6 | -------------------------------------------------------------------------------- /packages/expect-more/src/lib/is-jest-equal.ts: -------------------------------------------------------------------------------- 1 | import { curry2 } from './curry2'; 2 | import { isAsym } from './is-asym'; 3 | 4 | export const isJestEqual = curry2( 5 | (value: T, other: unknown): other is T => 6 | value === other || 7 | (isAsym(value) && value.asymmetricMatch(other)) || 8 | (isAsym(other) && other.asymmetricMatch(value)), 9 | ); 10 | -------------------------------------------------------------------------------- /packages/expect-more/src/lib/keys.ts: -------------------------------------------------------------------------------- 1 | export const keys = (object: Record): string[] => { 2 | const returnValue = []; 3 | for (const key in object) { 4 | if ({}.hasOwnProperty.call(object, key)) { 5 | returnValue.push(key); 6 | } 7 | } 8 | return returnValue; 9 | }; 10 | -------------------------------------------------------------------------------- /packages/expect-more/src/lib/some.ts: -------------------------------------------------------------------------------- 1 | import { UnaryBoolFn } from '../typings'; 2 | import { curry2 } from './curry2'; 3 | 4 | export const some = curry2((fn: UnaryBoolFn, array: any[]): array is any[] => { 5 | for (let i = 0, len = array.length; i < len; i++) { 6 | if (fn(array[i]) === true) { 7 | return true; 8 | } 9 | } 10 | return false; 11 | }); 12 | -------------------------------------------------------------------------------- /packages/expect-more/src/starts-with.ts: -------------------------------------------------------------------------------- 1 | import { isNonEmptyString } from './is-non-empty-string'; 2 | import { curry2 } from './lib/curry2'; 3 | 4 | /** 5 | * Asserts that value is a string whose trailing characters are equal to 6 | * those of the provided string. 7 | * @param otherString 'Java' 8 | * @param value 'JavaScript' 9 | * @matcherName toStartWith 10 | * @memberMatcherName toHaveStartingWith 11 | * @matcherMessage expected ${value} to start with ${otherString} 12 | * @matcherNotMessage expected ${value} not to start with ${otherString} 13 | */ 14 | export const startsWith = curry2( 15 | (otherString: string, value: unknown): value is string => 16 | isNonEmptyString(value) && 17 | isNonEmptyString(otherString) && 18 | value.slice(0, otherString.length) === otherString, 19 | ); 20 | -------------------------------------------------------------------------------- /packages/expect-more/src/throws-any-error.ts: -------------------------------------------------------------------------------- 1 | import type { AnyFn } from './typings'; 2 | 3 | /** 4 | * Asserts that a value is a `Function` which throws when invoked. 5 | * @param value () => { throw new Error("it wasn't me!") } 6 | * @matcherName toThrowAnyError 7 | * @memberMatcherName toHaveMethodThrowingAnyError 8 | * @matcherMessage expected ${value} to throw 9 | * @matcherNotMessage expected ${value} not to throw 10 | */ 11 | export const throwsAnyError = (value: T): value is T => { 12 | try { 13 | value(); 14 | return false; 15 | } catch (err) { 16 | return true; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /packages/expect-more/src/throws-error-of-type.ts: -------------------------------------------------------------------------------- 1 | import { curry2 } from './lib/curry2'; 2 | import { AnyFn } from './typings'; 3 | 4 | /** 5 | * Asserts that a value is a `Function` which throws an `Error` of the given 6 | * type. 7 | * @param typeName 'TypeError' 8 | * @param value () => thisValueIsUndefined.someProp 9 | * @matcherName toThrowErrorOfType 10 | * @memberMatcherName toHaveMethodThrowingErrorOfType 11 | * @matcherMessage expected ${value} to throw an error of type ${typeName} 12 | * @matcherNotMessage expected ${value} not to throw an error of type 13 | * ${typeName} 14 | */ 15 | export const throwsErrorOfType = curry2((typeName: string, value: AnyFn): value is AnyFn => { 16 | try { 17 | value(); 18 | return false; 19 | } catch (err) { 20 | return err.name === typeName; 21 | } 22 | }); 23 | -------------------------------------------------------------------------------- /packages/expect-more/src/typings.ts: -------------------------------------------------------------------------------- 1 | export type AnyFn = (...args: any[]) => any; 2 | export type Collection = any[] | Record; 3 | export type Reducer = (memo: any, value: any, key: number | string, collection: Collection) => any; 4 | export type UnaryBoolFn = (value: any) => boolean; 5 | export type VoidFn = () => void; 6 | -------------------------------------------------------------------------------- /packages/expect-more/test/ends-with.spec.ts: -------------------------------------------------------------------------------- 1 | import { endingWith, notEndingWith } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts case-sensitive string ending with another', 6 | endingWith, 7 | ([otherString, value]) => { 8 | expect(api.endsWith(otherString)(value)).toEqual(true); 9 | expect(api.endsWith(otherString, value)).toEqual(true); 10 | }, 11 | ); 12 | 13 | check.it('rejects otherwise', notEndingWith, ([otherString, value]) => { 14 | expect(api.endsWith(otherString)(value)).toEqual(false); 15 | expect(api.endsWith(otherString, value)).toEqual(false); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/expect-more/test/gen/index.spec.ts: -------------------------------------------------------------------------------- 1 | import gen = require('../../src/gen'); 2 | 3 | [ 4 | 'withMissingBranches', 5 | 'withMissingLeaves', 6 | 'withMissingNodes', 7 | 'withNullBranches', 8 | 'withNullLeaves', 9 | 'withNullNodes', 10 | ].forEach((method: string) => { 11 | it(`gen.${method} is exported`, () => { 12 | expect(gen[method]).toBeFunction(); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more/test/has-member.spec.ts: -------------------------------------------------------------------------------- 1 | import { gen } from 'testcheck'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is present (whether value is defined or not)', 6 | gen.primitive, 7 | (value) => { 8 | expect(api.hasMember('propName', { propName: value })).toEqual(true); 9 | expect(api.hasMember('propName')({ propName: value })).toEqual(true); 10 | }, 11 | ); 12 | 13 | it('rejects otherwise', () => { 14 | expect(api.hasMember('propName', {})).toEqual(false); 15 | expect(api.hasMember('propName')({})).toEqual(false); 16 | expect(api.hasMember('otherProp', { propName: true })).toEqual(false); 17 | expect(api.hasMember('otherProp')({ propName: true })).toEqual(false); 18 | }); 19 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-array-of-booleans.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrayOfBooleans, notArrayOfBooleans } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is a non-empty array containing only booleans', 6 | arrayOfBooleans, 7 | (value) => { 8 | expect(api.isArrayOfBooleans(value)).toEqual(true); 9 | }, 10 | ); 11 | 12 | check.it('rejects otherwise', notArrayOfBooleans, (value) => { 13 | expect(api.isArrayOfBooleans(value)).toEqual(false); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-array-of-numbers.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrayOfNumbers, notArrayOfNumbers } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is a non-empty array containing only numbers', 6 | arrayOfNumbers, 7 | (value) => { 8 | expect(api.isArrayOfNumbers(value)).toEqual(true); 9 | }, 10 | ); 11 | 12 | check.it('rejects otherwise', notArrayOfNumbers, (value) => { 13 | expect(api.isArrayOfNumbers(value)).toEqual(false); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-array-of-objects.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrayOfObjects, notArrayOfObjects } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is a non-empty array containing only objects', 6 | arrayOfObjects, 7 | (value) => { 8 | expect(api.isArrayOfObjects(value)).toEqual(true); 9 | }, 10 | ); 11 | 12 | check.it('rejects otherwise', notArrayOfObjects, (value) => { 13 | expect(api.isArrayOfObjects(value)).toEqual(false); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-array-of-size.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrayOfFiveItems, notArrayOfFiveItems } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is an array whose length matches the given number', 6 | arrayOfFiveItems, 7 | (value) => { 8 | expect(api.isArrayOfSize(5)(value)).toEqual(true); 9 | expect(api.isArrayOfSize(5, value)).toEqual(true); 10 | }, 11 | ); 12 | 13 | check.it('rejects otherwise', notArrayOfFiveItems, (value) => { 14 | expect(api.isArrayOfSize(5)(value)).toEqual(false); 15 | expect(api.isArrayOfSize(5, value)).toEqual(false); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-array-of-strings.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrayOfStrings, notArrayOfStrings } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is a non-empty array containing only strings', 6 | arrayOfStrings, 7 | (value) => { 8 | expect(api.isArrayOfStrings(value)).toEqual(true); 9 | }, 10 | ); 11 | 12 | check.it('rejects otherwise', notArrayOfStrings, (value) => { 13 | expect(api.isArrayOfStrings(value)).toEqual(false); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-array.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrays, notArrays } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is an array', arrays, (value) => { 5 | expect(api.isArray(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notArrays, (value) => { 9 | expect(api.isArray(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-async-function.spec.ts: -------------------------------------------------------------------------------- 1 | import { asyncFunctions, notAsyncFunctions } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is an async function', asyncFunctions, (value) => { 5 | expect(api.isAsyncFunction(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notAsyncFunctions, (value) => { 9 | expect(api.isAsyncFunction(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-boolean.spec.ts: -------------------------------------------------------------------------------- 1 | import { booleans, notBooleans } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a boolean', booleans, (value) => { 5 | expect(api.isBoolean(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notBooleans, (value) => { 9 | expect(api.isBoolean(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-calculable.spec.ts: -------------------------------------------------------------------------------- 1 | import { calculables, notCalculables } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is a value coercable to be used in mathematical operations', 6 | calculables, 7 | (value) => { 8 | expect(api.isCalculable(value)).toEqual(true); 9 | }, 10 | ); 11 | 12 | check.it('rejects otherwise', notCalculables, (value) => { 13 | expect(api.isCalculable(value)).toEqual(false); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-date-after.spec.ts: -------------------------------------------------------------------------------- 1 | import { dateAfter, notDateAfter } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is a date occurring after the date provided', 6 | dateAfter, 7 | ([otherDate, value]) => { 8 | expect(api.isAfter(otherDate)(value)).toEqual(true); 9 | expect(api.isAfter(otherDate, value)).toEqual(true); 10 | }, 11 | ); 12 | 13 | check.it('rejects otherwise', notDateAfter, ([otherDate, value]) => { 14 | expect(api.isAfter(otherDate)(value)).toEqual(false); 15 | expect(api.isAfter(otherDate, value)).toEqual(false); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-date-before.spec.ts: -------------------------------------------------------------------------------- 1 | import { dateBefore, notDateBefore } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is a date occurring before the date provided', 6 | dateBefore, 7 | ([otherDate, value]) => { 8 | expect(api.isBefore(otherDate)(value)).toEqual(true); 9 | expect(api.isBefore(otherDate, value)).toEqual(true); 10 | }, 11 | ); 12 | 13 | check.it('rejects otherwise', notDateBefore, ([otherDate, value]) => { 14 | expect(api.isBefore(otherDate)(value)).toEqual(false); 15 | expect(api.isBefore(otherDate, value)).toEqual(false); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-date-in-month.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | import { notDates } from '../../../test/fixtures'; 3 | 4 | it('passes when the date in local time falls on the given month', () => { 5 | [ 6 | '2021-01-10', 7 | '2021-02-10', 8 | '2021-03-10', 9 | '2021-04-10', 10 | '2021-05-10', 11 | '2021-06-10', 12 | '2021-07-10', 13 | '2021-08-10', 14 | '2021-09-10', 15 | '2021-10-10', 16 | '2021-11-10', 17 | '2021-12-10', 18 | ].forEach((iso8601, index) => { 19 | expect(api.isDateInMonth(index, new Date(iso8601))).toEqual(true); 20 | }); 21 | }); 22 | 23 | it('rejects otherwise', () => { 24 | expect(api.isDateInMonth(0, new Date('2021-04-10'))).toEqual(false); 25 | }); 26 | 27 | check.it('rejects non-date values', notDates, (value) => { 28 | expect(api.isDateInMonth(2, value)).toEqual(false); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-date-in-year.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | import { notDates } from '../../../test/fixtures'; 3 | 4 | it('passes when the date in local time falls on the given year', () => { 5 | expect(api.isDateInYear(1960, new Date('1960-01-01'))).toEqual(true); 6 | }); 7 | 8 | it('rejects otherwise', () => { 9 | expect(api.isDateInYear(1960, new Date('1961-01-01'))).toEqual(false); 10 | }); 11 | 12 | check.it('rejects non-date values', notDates, (value) => { 13 | expect(api.isDateInYear(2021, value)).toEqual(false); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-date-on-day-of-month.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | import { notDates } from '../../../test/fixtures'; 3 | 4 | it('passes when the date in local time falls on the given day (or "date") of the month', () => { 5 | expect(api.isDateOnDayOfMonth(1, new Date('1960-01-01'))).toEqual(true); 6 | expect(api.isDateOnDayOfMonth(5, new Date('2021-03-05'))).toEqual(true); 7 | }); 8 | 9 | it('rejects otherwise', () => { 10 | expect(api.isDateOnDayOfMonth(12, new Date('1960-01-01'))).toEqual(false); 11 | expect(api.isDateOnDayOfMonth(3, new Date('2021-03-05'))).toEqual(false); 12 | }); 13 | 14 | check.it('rejects non-date values', notDates, (value) => { 15 | expect(api.isDateOnDayOfMonth(5, value)).toEqual(false); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-date-on-day-of-week.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | import { notDates } from '../../../test/fixtures'; 3 | 4 | it('passes when the date in local time falls on the given day of the week', () => { 5 | expect(api.isDateOnDayOfWeek(5, new Date('1960-01-01'))).toEqual(true); 6 | expect(api.isDateOnDayOfWeek(5, new Date('2021-03-05'))).toEqual(true); 7 | }); 8 | 9 | it('rejects otherwise', () => { 10 | expect(api.isDateOnDayOfWeek(0, new Date('1960-01-01'))).toEqual(false); 11 | expect(api.isDateOnDayOfWeek(6, new Date('2021-03-05'))).toEqual(false); 12 | }); 13 | 14 | check.it('rejects non-date values', notDates, (value) => { 15 | expect(api.isDateOnDayOfWeek(5, value)).toEqual(false); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-date-on-or-after.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | import { notDates } from '../../../test/fixtures'; 3 | 4 | it('passes when the date in local time falls at the same time or after the given date', () => { 5 | [ 6 | ['2021-08-31', '2021-08-31'], 7 | ['2021-08-30', '2021-08-31'], 8 | ['2021-08-30T11:11:11', '2021-08-31T11:11:11'], 9 | ['2021-08-30T11:11:11', '2021-08-31T11:11:12'], 10 | ].forEach(([a, b]) => { 11 | expect(api.isDateOnOrAfter(new Date(a), new Date(b))).toEqual(true); 12 | }); 13 | }); 14 | 15 | it('rejects otherwise', () => { 16 | [ 17 | ['2021-09-01', '2021-08-31'], 18 | ['2021-08-30T11:11:11', '2021-08-30T11:11:10'], 19 | ].forEach(([a, b]) => { 20 | expect(api.isDateOnOrAfter(new Date(a), new Date(b))).toEqual(false); 21 | }); 22 | }); 23 | 24 | check.it('rejects non-date values', notDates, (value) => { 25 | expect(api.isDateOnOrAfter(5, value)).toEqual(false); 26 | }); 27 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-date-on-or-before.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | import { notDates } from '../../../test/fixtures'; 3 | 4 | it('passes when the date in local time falls at the same time or before the given date', () => { 5 | [ 6 | ['2021-08-31', '2021-08-31'], 7 | ['2021-08-31', '2021-08-30'], 8 | ['2021-08-31T11:11:11', '2021-08-30T11:11:11'], 9 | ['2021-08-31T11:11:12', '2021-08-30T11:11:11'], 10 | ].forEach(([a, b]) => { 11 | expect(api.isDateOnOrBefore(new Date(a), new Date(b))).toEqual(true); 12 | }); 13 | }); 14 | 15 | it('rejects otherwise', () => { 16 | [ 17 | ['2021-08-31', '2021-09-01'], 18 | ['2021-08-30T11:11:10', '2021-08-30T11:11:11'], 19 | ].forEach(([a, b]) => { 20 | expect(api.isDateOnOrBefore(new Date(a), new Date(b))).toEqual(false); 21 | }); 22 | }); 23 | 24 | check.it('rejects non-date values', notDates, (value) => { 25 | expect(api.isDateOnOrBefore(5, value)).toEqual(false); 26 | }); 27 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-date.spec.ts: -------------------------------------------------------------------------------- 1 | import { dates, notDates } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a date', dates, (value) => { 5 | expect(api.isDate(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notDates, (value) => { 9 | expect(api.isDate(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-decimal-number.spec.ts: -------------------------------------------------------------------------------- 1 | import { decimalNumbers, notDecimalNumbers } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a number with decimal places', decimalNumbers, (value) => { 5 | expect(api.isDecimalNumber(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notDecimalNumbers, (value) => { 9 | expect(api.isDecimalNumber(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-divisible-by.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | 3 | it('accepts if value is a number in the times table of another', () => { 4 | expect(api.isDivisibleBy(2, 6)).toEqual(true); 5 | expect(api.isDivisibleBy(2)(6)).toEqual(true); 6 | }); 7 | 8 | it('rejects otherwise', () => { 9 | expect(api.isDivisibleBy(2, 3)).toEqual(false); 10 | expect(api.isDivisibleBy(2)(3)).toEqual(false); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-empty-array.spec.ts: -------------------------------------------------------------------------------- 1 | import { emptyArrays, notEmptyArrays } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is an empty array', emptyArrays, (value) => { 5 | expect(api.isEmptyArray(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notEmptyArrays, (value) => { 9 | expect(api.isEmptyArray(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-empty-object.spec.ts: -------------------------------------------------------------------------------- 1 | import { emptyObjects, notEmptyObjects } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is an empty object', emptyObjects, (value) => { 5 | expect(api.isEmptyObject(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notEmptyObjects, (value) => { 9 | expect(api.isEmptyObject(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-empty-string.spec.ts: -------------------------------------------------------------------------------- 1 | import { emptyStrings, notEmptyStrings } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is an empty string', emptyStrings, (value) => { 5 | expect(api.isEmptyString(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notEmptyStrings, (value) => { 9 | expect(api.isEmptyString(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-even-number.spec.ts: -------------------------------------------------------------------------------- 1 | import { evenNumbers, notEvenNumbers } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is an even number', evenNumbers, (value) => { 5 | expect(api.isEvenNumber(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notEvenNumbers, (value) => { 9 | expect(api.isEvenNumber(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-false.spec.ts: -------------------------------------------------------------------------------- 1 | import { falses, notFalses } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is false', falses, (value) => { 5 | expect(api.isFalse(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notFalses, (value) => { 9 | expect(api.isFalse(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-function.spec.ts: -------------------------------------------------------------------------------- 1 | import { functions, notFunctions } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a function', functions, (value) => { 5 | expect(api.isFunction(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notFunctions, (value) => { 9 | expect(api.isFunction(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-generator-function.spec.ts: -------------------------------------------------------------------------------- 1 | import { generatorFunctions, notGeneratorFunctions } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a generator function', generatorFunctions, (value) => { 5 | expect(api.isGeneratorFunction(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notGeneratorFunctions, (value) => { 9 | expect(api.isGeneratorFunction(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-greater-than-or-equal-to.spec.ts: -------------------------------------------------------------------------------- 1 | import { notNumbers, numbers } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is a number greater than or equal to another', 6 | numbers, 7 | (value: number) => { 8 | expect(api.isGreaterThanOrEqualTo(value, value + 1)).toEqual(true); 9 | expect(api.isGreaterThanOrEqualTo(value)(value + 1)).toEqual(true); 10 | expect(api.isGreaterThanOrEqualTo(value, value)).toEqual(true); 11 | expect(api.isGreaterThanOrEqualTo(value)(value)).toEqual(true); 12 | }, 13 | ); 14 | 15 | check.it('rejects otherwise', notNumbers, (value) => { 16 | expect(api.isGreaterThanOrEqualTo(value, value)).toEqual(false); 17 | expect(api.isGreaterThanOrEqualTo(value)(value)).toEqual(false); 18 | }); 19 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-iso8601.spec.ts: -------------------------------------------------------------------------------- 1 | import { iso8601s, notIso8601s } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a valid ISO8601 date string', iso8601s, (value) => { 5 | expect(api.isIso8601(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notIso8601s, (value) => { 9 | expect(api.isIso8601(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-json-string.spec.ts: -------------------------------------------------------------------------------- 1 | import { jsonStrings, notJsonStrings } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a valid JSON string', jsonStrings, (value) => { 5 | expect(api.isJsonString(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notJsonStrings, (value) => { 9 | expect(api.isJsonString(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-less-than-or-equal-to.spec.ts: -------------------------------------------------------------------------------- 1 | import { notNumbers, numbers } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a number less than or equal to another', numbers, (value: number) => { 5 | expect(api.isLessThanOrEqualTo(value)(value - 1)).toEqual(true); 6 | expect(api.isLessThanOrEqualTo(value, value - 1)).toEqual(true); 7 | expect(api.isLessThanOrEqualTo(value)(value)).toEqual(true); 8 | expect(api.isLessThanOrEqualTo(value, value)).toEqual(true); 9 | }); 10 | 11 | check.it('rejects otherwise', notNumbers, (value) => { 12 | expect(api.isLessThanOrEqualTo(value)(value)).toEqual(false); 13 | expect(api.isLessThanOrEqualTo(value, value)).toEqual(false); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-longer-than.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | 3 | it('accepts if value is a string with a greater length than the provided string', () => { 4 | [ 5 | ['ab', 'abc'], 6 | ['', 'a'], 7 | ].forEach(([other, value]) => { 8 | expect(api.isLongerThan(other, value)).toEqual(true); 9 | expect(api.isLongerThan(other)(value)).toEqual(true); 10 | }); 11 | }); 12 | 13 | it('accepts if value is an array with a greater length than the provided array', () => { 14 | [ 15 | [ 16 | [5, 2], 17 | [7, 3, 1], 18 | ], 19 | [[], [3]], 20 | ].forEach(([other, value]) => { 21 | expect(api.isLongerThan(other, value)).toEqual(true); 22 | expect(api.isLongerThan(other)(value)).toEqual(true); 23 | }); 24 | }); 25 | 26 | it('rejects otherwise', () => { 27 | [ 28 | ['ab', 'a'], 29 | ['ab', undefined], 30 | ['ab', null], 31 | ].forEach(([other, value]) => { 32 | expect(api.isLongerThan(other, value)).toEqual(false); 33 | expect(api.isLongerThan(other)(value)).toEqual(false); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-near.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | 3 | it('accepts if value is no more than epsilion larger or smaller than another', () => { 4 | [ 5 | [4, 0.25, 4.23223432434], 6 | [20, 2, 22], 7 | [-40, 2, -42], 8 | ].forEach(([otherNumber, epsilon, value]) => { 9 | expect(api.isNear(otherNumber)(epsilon)(value)).toEqual(true); 10 | expect(api.isNear(otherNumber)(epsilon, value)).toEqual(true); 11 | expect(api.isNear(otherNumber, epsilon)(value)).toEqual(true); 12 | expect(api.isNear(otherNumber, epsilon, value)).toEqual(true); 13 | }); 14 | }); 15 | 16 | it('rejects otherwise', () => { 17 | [ 18 | [4, 0.2, 4.23223432434], 19 | [20, 1, 22], 20 | [-18, 11, -42], 21 | ].forEach(([otherNumber, epsilon, value]) => { 22 | expect(api.isNear(otherNumber)(epsilon)(value)).toEqual(false); 23 | expect(api.isNear(otherNumber, epsilon, value)).toEqual(false); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-negative-number.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | import { notNumbers } from '../../../test/fixtures'; 3 | 4 | it('passes when value is a number below or equal to zero', () => { 5 | expect(api.isNegativeNumber(-1)).toEqual(true); 6 | expect(api.isNegativeNumber(-0.01)).toEqual(true); 7 | expect(api.isNegativeNumber(new Number(-0.01))).toEqual(true); 8 | }); 9 | 10 | it('rejects otherwise', () => { 11 | expect(api.isNegativeNumber(1)).toEqual(false); 12 | expect(api.isNegativeNumber(0.01)).toEqual(false); 13 | expect(api.isNegativeNumber(0)).toEqual(false); 14 | expect(api.isNegativeNumber(-0)).toEqual(false); 15 | }); 16 | 17 | check.it('rejects values which are not numbers', notNumbers, (value) => { 18 | expect(api.isNegativeNumber(value)).toEqual(false); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-nil.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | 3 | it('passes when a value is null or undefined', () => { 4 | expect(api.isNil(undefined)).toEqual(true); 5 | expect(api.isNil(void 0)).toEqual(true); 6 | expect(api.isNil(null)).toEqual(true); 7 | }); 8 | 9 | it('rejects otherwise', () => { 10 | expect(api.isNil(0)).toEqual(false); 11 | expect(api.isNil('')).toEqual(false); 12 | expect(api.isNil(false)).toEqual(false); 13 | expect(api.isNil({})).toEqual(false); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-non-empty-array.spec.ts: -------------------------------------------------------------------------------- 1 | import { nonEmptyArrays, notNonEmptyArrays } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is an array with at least one member', nonEmptyArrays, (value) => { 5 | expect(api.isNonEmptyArray(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notNonEmptyArrays, (value) => { 9 | expect(api.isNonEmptyArray(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-non-empty-object.spec.ts: -------------------------------------------------------------------------------- 1 | import { nonEmptyObjects, notNonEmptyObjects } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is an object with at least one member', nonEmptyObjects, (value) => { 5 | expect(api.isNonEmptyObject(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notNonEmptyObjects, (value) => { 9 | expect(api.isNonEmptyObject(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-non-empty-string.spec.ts: -------------------------------------------------------------------------------- 1 | import { nonEmptyStrings, notNonEmptyStrings } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a string with at least one character', nonEmptyStrings, (value) => { 5 | expect(api.isNonEmptyString(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notNonEmptyStrings, (value) => { 9 | expect(api.isNonEmptyString(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-number.spec.ts: -------------------------------------------------------------------------------- 1 | import { notNumbers, numbers } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a number', numbers, (value) => { 5 | expect(api.isNumber(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notNumbers, (value) => { 9 | expect(api.isNumber(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-object.spec.ts: -------------------------------------------------------------------------------- 1 | import { notObjects, objects } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is an object', objects, (value) => { 5 | expect(api.isObject(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notObjects, (value) => { 9 | expect(api.isObject(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-odd-number.spec.ts: -------------------------------------------------------------------------------- 1 | import { notOddNumbers, oddNumbers } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is an odd number', oddNumbers, (value) => { 5 | expect(api.isOddNumber(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notOddNumbers, (value) => { 9 | expect(api.isOddNumber(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-positive-number.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | import { notNumbers } from '../../../test/fixtures'; 3 | 4 | it('passes when value is a number above or equal to zero', () => { 5 | expect(api.isPositiveNumber(1)).toEqual(true); 6 | expect(api.isPositiveNumber(0.01)).toEqual(true); 7 | expect(api.isPositiveNumber(new Number(0.01))).toEqual(true); 8 | }); 9 | 10 | it('rejects otherwise', () => { 11 | expect(api.isPositiveNumber(-1)).toEqual(false); 12 | expect(api.isPositiveNumber(-0.01)).toEqual(false); 13 | expect(api.isPositiveNumber(0)).toEqual(false); 14 | expect(api.isPositiveNumber(-0)).toEqual(false); 15 | }); 16 | 17 | check.it('rejects values which are not numbers', notNumbers, (value) => { 18 | expect(api.isPositiveNumber(value)).toEqual(false); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-reg-exp.spec.ts: -------------------------------------------------------------------------------- 1 | import { notRegExs, regExs } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a regular expression', regExs, (value) => { 5 | expect(api.isRegExp(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notRegExs, (value) => { 9 | expect(api.isRegExp(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-same-length-as.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | 3 | it('accepts if value is a string with the same length than the provided string', () => { 4 | [ 5 | ['abc', 'abc'], 6 | ['a', 'a'], 7 | ['', ''], 8 | ].forEach(([other, value]) => { 9 | expect(api.isSameLengthAs(other, value)).toEqual(true); 10 | expect(api.isSameLengthAs(other)(value)).toEqual(true); 11 | }); 12 | }); 13 | 14 | it('accepts if value is an array with the same length than the provided array', () => { 15 | [ 16 | [ 17 | [4, 2, 6], 18 | [7, 4, 6], 19 | ], 20 | [ 21 | [8, 9], 22 | [0, 0], 23 | ], 24 | ].forEach(([other, value]) => { 25 | expect(api.isSameLengthAs(other, value)).toEqual(true); 26 | expect(api.isSameLengthAs(other)(value)).toEqual(true); 27 | }); 28 | }); 29 | 30 | it('rejects otherwise', () => { 31 | [ 32 | ['a', 'abc'], 33 | ['ab', undefined], 34 | ['ab', null], 35 | ].forEach(([other, value]) => { 36 | expect(api.isSameLengthAs(other, value)).toEqual(false); 37 | expect(api.isSameLengthAs(other)(value)).toEqual(false); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-shorter-than.spec.ts: -------------------------------------------------------------------------------- 1 | import api = require('../src'); 2 | 3 | it('accepts if value is a string with a shorter length than the provided string', () => { 4 | [ 5 | ['abc', 'ab'], 6 | ['a', ''], 7 | ].forEach(([other, value]) => { 8 | expect(api.isShorterThan(other, value)).toEqual(true); 9 | expect(api.isShorterThan(other)(value)).toEqual(true); 10 | }); 11 | }); 12 | 13 | it('accepts if value is an array with a shorter length than the provided array', () => { 14 | [ 15 | [ 16 | [2, 5, 1], 17 | [8, 4], 18 | ], 19 | [[1], []], 20 | ].forEach(([other, value]) => { 21 | expect(api.isShorterThan(other, value)).toEqual(true); 22 | expect(api.isShorterThan(other)(value)).toEqual(true); 23 | }); 24 | }); 25 | 26 | it('rejects otherwise', () => { 27 | [ 28 | ['a', 'abc'], 29 | ['ab', undefined], 30 | ['ab', null], 31 | ].forEach(([other, value]) => { 32 | expect(api.isShorterThan(other, value)).toEqual(false); 33 | expect(api.isShorterThan(other)(value)).toEqual(false); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-string.spec.ts: -------------------------------------------------------------------------------- 1 | import { notStrings, strings } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a string', strings, (value) => { 5 | expect(api.isString(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notStrings, (value) => { 9 | expect(api.isString(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-true.spec.ts: -------------------------------------------------------------------------------- 1 | import { notTrues, trues } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is true', trues, (value) => { 5 | expect(api.isTrue(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notTrues, (value) => { 9 | expect(api.isTrue(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-undefined.spec.ts: -------------------------------------------------------------------------------- 1 | import { notUndefineds, undefineds } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is undefined', undefineds, (value) => { 5 | expect(api.isUndefined(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notUndefineds, (value) => { 9 | expect(api.isUndefined(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-valid-date.spec.ts: -------------------------------------------------------------------------------- 1 | import { dates, notValidDates } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is an instance of Date and its date is valid', dates, (value) => { 5 | expect(api.isValidDate(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notValidDates, (value) => { 9 | expect(api.isValidDate(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-visible-string.spec.ts: -------------------------------------------------------------------------------- 1 | import { notVisibleStrings, visibleStrings } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is a string with at least one non-whitespace character', 6 | visibleStrings, 7 | (value) => { 8 | expect(api.isVisibleString(value)).toEqual(true); 9 | }, 10 | ); 11 | 12 | check.it('rejects otherwise', notVisibleStrings, (value) => { 13 | expect(api.isVisibleString(value)).toEqual(false); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-walkable.spec.ts: -------------------------------------------------------------------------------- 1 | import { notWalkables, walkables } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is able to have members', walkables, (value) => { 5 | expect(api.isWalkable(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notWalkables, (value) => { 9 | expect(api.isWalkable(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-whitespace.spec.ts: -------------------------------------------------------------------------------- 1 | import { notWhitespaceStrings, whitespaceStrings } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is a non-empty string containing only whitespace', 6 | whitespaceStrings, 7 | (value) => { 8 | expect(api.isWhitespace(value)).toEqual(true); 9 | }, 10 | ); 11 | 12 | check.it('rejects otherwise', notWhitespaceStrings, (value) => { 13 | expect(api.isWhitespace(value)).toEqual(false); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-whole-number.spec.ts: -------------------------------------------------------------------------------- 1 | import { notWholeNumbers, wholeNumbers } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if value is a number with no decimal places', wholeNumbers, (value) => { 5 | expect(api.isWholeNumber(value)).toEqual(true); 6 | }); 7 | 8 | check.it('rejects otherwise', notWholeNumbers, (value) => { 9 | expect(api.isWholeNumber(value)).toEqual(false); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/expect-more/test/is-within-range.spec.ts: -------------------------------------------------------------------------------- 1 | import { notNumbersWithinRange, numbersWithinRange } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if value is a number falling within the given range', 6 | numbersWithinRange, 7 | (value) => { 8 | expect(api.isWithinRange(8, 15, value)).toEqual(true); 9 | expect(api.isWithinRange(8, 15)(value)).toEqual(true); 10 | expect(api.isWithinRange(8)(15)(value)).toEqual(true); 11 | }, 12 | ); 13 | 14 | check.it('rejects otherwise', notNumbersWithinRange, (value) => { 15 | expect(api.isWithinRange(8, 15, value)).toEqual(false); 16 | expect(api.isWithinRange(8)(15)(value)).toEqual(false); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/expect-more/test/starts-with.spec.ts: -------------------------------------------------------------------------------- 1 | import { notStartingWith, startingWith } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts case-sensitive string starting with another', 6 | startingWith, 7 | ([otherString, value]) => { 8 | expect(api.startsWith(otherString)(value)).toEqual(true); 9 | expect(api.startsWith(otherString, value)).toEqual(true); 10 | }, 11 | ); 12 | 13 | check.it('rejects otherwise', notStartingWith, ([otherString, value]) => { 14 | expect(api.startsWith(otherString)(value)).toEqual(false); 15 | expect(api.startsWith(otherString, value)).toEqual(false); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/expect-more/test/throws-any-error.spec.ts: -------------------------------------------------------------------------------- 1 | import { errorConstructors } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it('accepts if function throws any type of error when called', errorConstructors, (Err) => { 5 | expect( 6 | api.throwsAnyError(() => { 7 | throw new Err('wut?'); 8 | }), 9 | ).toEqual(true); 10 | }); 11 | 12 | it('rejects otherwise', () => { 13 | expect( 14 | api.throwsAnyError(() => { 15 | /* */ 16 | }), 17 | ).toEqual(false); 18 | }); 19 | -------------------------------------------------------------------------------- /packages/expect-more/test/throws-error-of-type.spec.ts: -------------------------------------------------------------------------------- 1 | import { errorConstructors } from '../../../test/fixtures'; 2 | import api = require('../src'); 3 | 4 | check.it( 5 | 'accepts if function throws error of the given type when called', 6 | errorConstructors, 7 | (Err) => { 8 | const neverGonna = () => { 9 | throw new Err('wut?'); 10 | }; 11 | expect(api.throwsErrorOfType(Err.name, neverGonna)).toEqual(true); 12 | expect(api.throwsErrorOfType(Err.name)(neverGonna)).toEqual(true); 13 | }, 14 | ); 15 | 16 | it('rejects otherwise', () => { 17 | expect(api.throwsErrorOfType('Error', () => 1)).toEqual(false); 18 | expect(api.throwsErrorOfType('Error')(() => 1)).toEqual(false); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/expect-more/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "include": ["./src/**/*.ts"], 4 | "compilerOptions": { 5 | "outDir": "./dist" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /scripts/generate-matchers.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ts-node --project ./scripts/tsconfig.json ./scripts/generate-matchers/index.ts \ 4 | && yarn build \ 5 | && yarn lint 6 | -------------------------------------------------------------------------------- /scripts/generate-matchers/jasmine-index.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs'; 2 | import * as path from 'path'; 3 | import { camelToKebab, FileMeta } from './index'; 4 | import { expectMoreJasminePath } from './paths'; 5 | 6 | export const generateJasmineIndex = ( 7 | matcherMetadata: FileMeta[], 8 | memberMatcherMetadata: FileMeta[], 9 | ): void => { 10 | const toJasmineExport = (name) => `export { ${name}Matcher } from './${camelToKebab(name)}';`; 11 | const indexPath = path.resolve(expectMoreJasminePath, './index.ts'); 12 | const source = [] 13 | .concat( 14 | matcherMetadata.map(({ jsDoc }) => toJasmineExport(jsDoc.matcherName)), 15 | memberMatcherMetadata.map(({ jsDoc }) => toJasmineExport(jsDoc.memberMatcherName)), 16 | ) 17 | .sort() 18 | .join('\n'); 19 | fs.writeFileSync(indexPath, source, 'utf8'); 20 | }; 21 | -------------------------------------------------------------------------------- /scripts/generate-matchers/jest-index.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs'; 2 | import * as path from 'path'; 3 | import { camelToKebab } from './index'; 4 | import { expectMoreJestPath } from './paths'; 5 | 6 | export const generateJestIndex = (): void => { 7 | const toJestExport = (name) => `export { ${name}Matcher } from './${camelToKebab(name)}';`; 8 | const kebabToCamel = (kebab) => kebab.replace(/-[a-z]/g, (a) => a[1].toUpperCase()); 9 | const indexPath = path.resolve(expectMoreJestPath, './index.ts'); 10 | const source = fs 11 | .readdirSync(expectMoreJestPath) 12 | .filter((location) => location.endsWith('.ts') && location !== 'index.ts') 13 | .map((filename) => toJestExport(kebabToCamel(filename.replace('.ts', '')))) 14 | .sort() 15 | .join('\n'); 16 | fs.writeFileSync(indexPath, source, 'utf8'); 17 | }; 18 | -------------------------------------------------------------------------------- /scripts/generate-matchers/paths.ts: -------------------------------------------------------------------------------- 1 | import { readdirSync } from 'fs'; 2 | import { resolve } from 'path'; 3 | 4 | const getFiles = (dirPath) => 5 | readdirSync(dirPath) 6 | .filter( 7 | (filename) => 8 | filename.endsWith('.ts') && 9 | !filename.endsWith('index.ts') && 10 | !filename.endsWith('typings.ts'), 11 | ) 12 | .map((filename) => resolve(dirPath, filename)); 13 | 14 | const rootDir = resolve(__dirname, '../..'); 15 | const expectMorePath = resolve(rootDir, './packages/expect-more/src'); 16 | const expectMoreLibPath = resolve(expectMorePath, './lib'); 17 | const libFilePaths = getFiles(expectMoreLibPath); 18 | 19 | export const expectMoreJasminePath = resolve(rootDir, './packages/expect-more-jasmine/src'); 20 | export const expectMoreJestPath = resolve(rootDir, './packages/expect-more-jest/src'); 21 | export const rootFilePaths = getFiles(expectMorePath); 22 | export const allFilePaths = [...rootFilePaths, ...libFilePaths]; 23 | -------------------------------------------------------------------------------- /scripts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "esModuleInterop": true, 4 | "forceConsistentCasingInFileNames": true, 5 | "lib": ["dom", "es6"], 6 | "target": "es5", 7 | "types": ["node"] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/index.ts: -------------------------------------------------------------------------------- 1 | export * from './negative'; 2 | export * from './positive'; 3 | -------------------------------------------------------------------------------- /test/jasmine-helper.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JamieMason/expect-more/b7a1710ab6860edf409c5880c0ba0afc7b12931f/test/jasmine-helper.ts -------------------------------------------------------------------------------- /test/setup-test-framework-script-file.ts: -------------------------------------------------------------------------------- 1 | import '../packages/expect-more-jest/src'; 2 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "downlevelIteration": true, 5 | "forceConsistentCasingInFileNames": true, 6 | "lib": ["es6"], 7 | "target": "es3", 8 | "types": [] 9 | } 10 | } 11 | --------------------------------------------------------------------------------