Skip to content

It's not possible to clear the value of paddingLeft by assigning an empty string to it. #1363

@rxy001

Description

@rxy001
  • @testing-library/dom version: 10.4.0
  • Testing Framework and version:
    "jest": "29.7.0",
  • DOM Environment:
    "@testing-library/jest-dom": "6.6.3",
    "jest-environment-jsdom": "29.7.0",

Relevant code or config:

document.body.style.paddingTop = '30px'
expect(document.body.style.paddingTop).toBe('30px')

document.body.style.paddingTop = ''
expect(document.body.style.paddingTop).toBe('') // error: Received: "30px"

jest.config.js

const jestConfig = {
  verbose: true,
  testMatch: [
    '<rootDir>/packages/**/__tests__/**/*.{spec,test}.{js,jsx,ts,tsx}',
  ],
  moduleNameMapper: {
    '^~/(.*)$': '<rootDir>/$1',
  },
  transform: {
    '^.+\\.(t|j)sx?$': [
      '@swc/jest',
      {
        jsc: {
          parser: {
            tsx: true,
            syntax: 'typescript',
          },
          transform: {
            react: {
              runtime: 'automatic',
            },
          },
        },
      },
    ],
    '.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
      'jest-transform-stub',
    '^.+\\.svg$': 'jest-transformer-svg',
  },
  transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
  // collectCoverage: true,
  collectCoverageFrom: ['packages/**/*.{ts,tsx}'],
  testEnvironment: 'jsdom',
  coverageDirectory: 'coverage',
  setupFilesAfterEnv: ['<rootDir>/tests/jest.setup.ts'],
  watchman: true,
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
}

Problem description:

Assigning an empty string to paddingTop is intended to clear its value, yet it actually retains the original value. This behavior is consistent with paddingLeft、paddingRight and paddingBottom. In contrast, padding can be properly cleared by assigning an empty string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions