Skip to content

fix: isNotEmptyObject nullable option works opposite wayΒ #1554

Open
@arkist

Description

@arkist

Description

nullable option for @IsNotEmptyObject but it works the opposite way.

Expected behavior

expected behavior from previous example in #678 is:

class MyClass {
  @IsNotEmptyObject()
  notStrictModeInvalid = { }; // invalid

  @IsNotEmptyObject()
  notStrictModeValid = { key1: null, key2: undefined }; // valid

  @IsNotEmptyObject({ nullable: false })
  strcitModeInvalid = { }; // invalid

  @IsNotEmptyObject({ nullable: false })
  strcitModeValid = { key1: null, key2: undefined }; // invalid

  @IsNotEmptyObject({ nullable: false })
  strcitModeValid = { key1: 'key', key2: undefined }; // valid
}

Actual behavior

in the current test suite, there's no test for nullable: false case.
for nullable: true testing, null and undefined are being treated as invalid values.

here are some tests to prove:

// FAIL
expect(
  isNotEmptyObject({ key1: null, key2: undefined }, { nullable: false })
).toBeFalsy()

// FAIL
expect(
  isNotEmptyObject({ key1: null, key2: undefined }, { nullable: true })
).toBeTruthy()

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: fixedIssues with merged PRs, but not released yet.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions