Skip to content

toHaveAttrs

Assert multiple cell attributes at once. Only specified fields are checked.

Signature

typescript
expect(cell).toHaveAttrs(attrs: CellAttrs)

Parameters

ParameterTypeDescription
attrs.boldbooleanBold styling
attrs.italicbooleanItalic styling
attrs.dimbooleanDim/faint styling
attrs.strikethroughbooleanStrikethrough styling
attrs.inversebooleanInverse/reverse video
attrs.widebooleanDouble-width character
attrs.underlineboolean | UnderlineStyletrue = any style, or specific style
attrs.fgstring | RGBForeground color (hex or RGB object)
attrs.bgstring | RGBBackground color (hex or RGB object)

All fields are optional. Only specified fields are checked.

Usage

typescript
// Single attribute
expect(term.cell(0, 0)).toHaveAttrs({ bold: true })

// Multiple attributes
expect(term.cell(0, 0)).toHaveAttrs({ bold: true, fg: "#ff0000" })

// Underline with specific style
expect(term.cell(5, 3)).toHaveAttrs({ italic: true, underline: "curly" })

// Any underline
expect(term.cell(0, 0)).toHaveAttrs({ underline: true })

// Negation
expect(term.cell(0, 0)).not.toHaveAttrs({ bold: true })

Error Messages

When an assertion fails, the message shows which specific attributes matched and which failed:

Expected cell (0,0) containing 'H' to have attrs {"bold":true,"fg":"#ff0000"}
  bold: expected true, got false
  fg: matched

Accepts

RegionSupported
term.cell(r, c)Yes
term.screenNo
term.row(n)No

Replaces

This composable matcher replaces 9 individual matchers:

Old MatcherEquivalent
toBeBold()toHaveAttrs({ bold: true })
toBeItalic()toHaveAttrs({ italic: true })
toBeDim()toHaveAttrs({ dim: true })
toBeStrikethrough()toHaveAttrs({ strikethrough: true })
toBeInverse()toHaveAttrs({ inverse: true })
toBeWide()toHaveAttrs({ wide: true })
toHaveUnderline(style?)toHaveAttrs({ underline: style || true })
toHaveFg(color)toHaveAttrs({ fg: color })
toHaveBg(color)toHaveAttrs({ bg: color })

The old matchers are deprecated but still work.

See Also

  • toHaveCursor - composable cursor assertions
  • toBeBold - individual bold assertion (deprecated)
  • toHaveFg - individual foreground color assertion (deprecated)