@angular-package/testing
Version:
Jasmine unit testing wrapper with additional custom testing features.
1 lines • 8.93 kB
JavaScript
import{is,typeOf}from"@angular-package/type";import{Expect}from"../expect.class";import{TestingExpect}from"../testing-expect.class";import{TestingExpectToBeArrayOf}from"./testing-expect-to-be-arrayof.class";import{TestingExpectToBeInstanceOf}from"./testing-expect-to-be-instanceof.class";export class TestingExpectToBe extends Expect{get arrayof(){return this.toBeArrayOf}get instanceof(){return this.toBeInstanceOf}toBeArrayOf;toBeInstanceOf;expectationFailOutput="The expected value should";constructor(t=new TestingExpect){super(t),this.toBeArrayOf=new TestingExpectToBeArrayOf(t),this.toBeInstanceOf=new TestingExpectToBeInstanceOf(t)}array(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be an \`array\``){return this.be(is.array(t),e,i),this}be(t,e,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be \`expected\``){return this.expect(t,i).toBe(e),this.setNot(!1),this}bigint(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be \`bigint\``){return this.be(is.bigint(t),e,i),this}boolean(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`boolean\` type or an instance of \`Boolean\``){return this.be(is.boolean(t),e,i),this}booleanType(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`boolean\` type`){return this.be(is.booleanType(t),e,i),this}class(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be \`class\``){return this.be(is.class(t),e,i),this}closeTo(t,e,i,s=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be close to \`expected\``){return this.expect(t,s).toBeCloseTo(e,i),this.setNot(!1),this}date(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`date\``){return this.be(is.date(t),e,i),this}defined(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be defined`){return!1===e&&this.not,this.expect(t,i).toBeDefined(),this.setNot(!1),this}false(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be equal to \`false\``){return!1===e&&this.not,this.expect(t,i).toBeFalse(),this.setNot(!1),this}falsy(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be falsy`){return!1===e&&this.not,this.expect(t,i).toBeFalsy(),this.setNot(!1),this}function(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be \`function\``){return this.be(is.function(t),e,i),this}greaterThan(t,e,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be greater than \`expected\``){return this.expect(t,i).toBeGreaterThan(e),this.setNot(!1),this}greaterThanOrEqual(t,e,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be greater or equal than \`expected\``){return this.expect(t,i).toBeGreaterThanOrEqual(e),this.setNot(!1),this}instance(t,e,i=!0,s=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be an instance of ${e.name}`){return this.be(is.instance(t,e),i,s),this}instanceOf(t,e,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be an instance of \`expected\``){return this.expect(t,i).toBeInstanceOf(e),this.setNot(!1),this}key(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be the property key`){return this.be(is.key(t),e,i),this}lessThan(t,e,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be less than \`expected\``){return this.expect(t,i).toBeLessThan(e),this.setNot(!1),this}lessThanOrEqual(t,e,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be less or equal than \`expected\``){return this.expect(t,i).toBeLessThanOrEqual(e),this.setNot(!1),this}naN(t,e=!0,i){return!1===e&&this.not,this.expect(t,i).toBeNaN(),this.setNot(!1),this}negativeInfinity(t,e=!0,i){return!1===e&&this.not,this.expect(t,i).toBeNegativeInfinity(),this.setNot(!1),this}null(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be \`null\``){return!1===e&&this.not,this.expect(t,i).toBeNull(),this.setNot(!1),this}number(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`number\` type or an instance of a \`Number\``){return this.be(is.number(t),e,i),this}numberBetween(t,e,i,s=!0,n=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`number\` type or an instance of a \`Number\` between the range of ${e} and ${i}`){return this.be(is.numberBetween(t,e,i),s,n),this}numberType(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`number\` type`){return this.be(is.numberType(t),e,i),this}object(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be an \`object\``){return this.be(is.object(t),e,i),this}objectKey(t,e,i=!0,s=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be an \`object\` with a given \`key\``){return this.be(is.objectKey(t,e),i,s),this}objectKeyIn(t,e,i=!0,s=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be an \`object\` with a given \`key\` in it(or its prototype chain)`){return this.be(is.objectKeyIn(t,e),i,s),this}objectKeys(t,e,i=!0,s=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be an \`object\` with given \`keys\``){return this.be(is.objectKeys(t,e),i,s),this}objectKeysIn(t,e,i=!0,s=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be an \`object\` with given \`keys\` in it(or its prototype chain)`){return this.be(is.objectKeysIn(t,e),i,s),this}objectSomeKeys(t,e,i=!0,s=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be an \`object\` with some of its keys or some groups of its keys from given \`keys\``){return this.be(is.objectSomeKeys(t,e),i,s),this}pending(t,e){return this.expectAsync(t,e).toBePending(),this.setAlready(!1).setNot(!1),this}positiveInfinity(t,e=!0,i){return!1===e&&this.not,this.expect(t,i).toBePositiveInfinity(),this.setNot(!1),this}regexp(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be \`RegExp\``){return this.be(is.regexp(t),e,i),this}rejected(t,e=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be rejected`){return this.expectAsync(t,e).toBeRejected(),this.setAlready(!1).setNot(!1),this}rejectedWith(t,e,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be rejected with \`expected\``){return this.expectAsync(t,i).toBeRejectedWith(e),this.setAlready(!1).setNot(!1),this}rejectedWithError(t,e,i,s=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be resolved with error`){return this.expectAsync(t,s).toBeRejectedWithError(e,i),this.setAlready(!1).setNot(!1),this}resolved(t,e=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be resolved`){return this.expectAsync(t,e).toBeResolved(),this.setAlready(!1).setNot(!1),this}resolvedTo(t,e,i){return this.expectAsync(t,i).toBeResolvedTo(e),this.setAlready(!1).setNot(!1),this}string(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`string\` type or an instance of a \`String\``){return this.be(is.string(t),e,i),this}stringIncludes(t,e,i=!0,s=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`string\` type or an instance of \`String\` that includes the specified words/sentences from a given \`includes\``){return this.be(is.stringIncludes(t,e),i,s),this}stringIncludesSome(t,e,i=!0,s=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`string\` type or an instance of \`String\` that includes some of the specified words/sentences from a given \`includes\``){return this.be(is.stringIncludesSome(t,e),i,s),this}stringOfLength(t,e,i=!0,s=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`string\` type or an instance of a \`String\` of the specified \`length\` equal to ${e}`){return this.be(is.stringLength(t,e),i,s),this}stringOfLengthBetween(t,e,i,s=!0,n=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`string\` type or an instance of a \`String\` of the \`length\` between the given ${e} and ${i}`){return this.be(is.stringLengthBetween(t,e,i),s,n),this}stringType(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`string\` type`){return this.be(is.stringType(t),e,i),this}symbol(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be a \`symbol\``){return this.be(is.symbol(t),e,i),this}true(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be equal to \`true\``){return!1===e&&this.not,this.expect(t,i).toBeTrue(),this.setNot(!1),this}truthy(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be truthy`){return!1===e&&this.not,this.expect(t,i).toBeTruthy(),this.setNot(!1),this}typeOf(t,e,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be typeOf`){return this.expect(typeOf(t)===e,i).toBeTrue(),this.setNot(!1),this}undefined(t,e=!0,i=`${this.expectationFailOutput} ${!0===this.getNot()?"not":""} be \`undefined\``){return!1===e&&this.not,this.expect(t,i).toBeUndefined(),this.setNot(!1),this}}