object-property
{ name, price } { price } This mutator removes one property or spread from an object literal, as if the
code left out a value: { name, price } becomes { price }.
Tests catch these
mutants when they check the removed property, or a value that a removed spread
copies, such as the cart total in { ...cart, coupon }.
Each property and spread gets its own mutant:
| Code | Mutant |
|---|---|
{ |
{ price } |
{ |
{ quantity } |
{ |
{ coupon } |
{ ...cart |
{ ...cart } |
In recommended, Mootant doesn’t remove a property that has a mutant inside: in
{ code, rate: 0.1 }, it removes code but not rate: 0.1, because
number-literal changes 0.1. A mutant of
optional-chaining doesn’t count:
{ name: user?.name, total } still becomes { total }.
With coarseMutants, on in strict,
Mootant removes such properties too: { code → , rate: 0.1 }{ code }.
Mootant leaves alone the label of a child logger, as in
logger.child({ module: 'checkout' }), but not a label with a call, such as
{ requestId: getId() }. The loggers setting
names the loggers.
Check the property that the mutant removes. For a removed spread, check a value that comes from that spread. Take this function:
export function applyCoupon(
cart: { total: number },
coupon: string,
): { total: number; coupon: string } {
return { ...cart, coupon }
return { coupon }
}A test that checks only the coupon does not catch { →
...cart, coupon }{ coupon }, because the coupon is still there. Compare the whole result:
it('keeps the cart total and adds the coupon', () => {
expect(applyCoupon({ total: 30 }, 'SAVE10')).toEqual({
total: 30,
coupon: 'SAVE10',
})
})With the mutant, applyCoupon({ total: 30 }, 'SAVE10') returns
{ coupon: 'SAVE10' }, without total. The same test catches
{ ...cart → , coupon }{ ...cart }, which returns { total: 30 }.
Other cases need these checks:
{ ...defaults→, currency}{ ...defaults }: pass acurrencyother thandefaults.currency.- A method or a getter: call the method, or read the getter.
sendMail({ to, subject }): check the call withtoHaveBeenCalledWith.
Turn the mutator off in the configuration:
import { defineConfig } from 'mootant'
export default defineConfig({
mutators: {
'object-property': 'off',
},
})To ignore the mutants of this mutator on one line, put an ignore comment above it:
// mootant-ignore-next-line object-property, statement-removal: logging only
logger.info({ orderId, total }, 'Order paid')Without statement-removal in the list, the line
gets → logger.info({ orderId, total }, 'Order paid');. Turning this mutator
off brings back that mutant too.
This mutator has no options.
Mootant leaves out these changes. npx mootant list src --skipped shows them
with the category and the rule; Skipped changes
explains the categories.
| Change | Reason |
|---|---|
{ code, rate: 0.1 }→{ code } | Removes code that has a finer mutant insidesubsumedsolitary |
{ sku: String }→{} in defineProps() | Read by the Vue or Svelte compiler as writteninvalidcompiler-macro |
{ style: 'decimal' }→{} | Removes an Intl option equal to its defaultequivalentdefault-option |
{ page, done }→{ page } | May keep a loop running forevertimeoutloop-advance |
{ id, id, total }→{ id, total } | Same code as another mutantduplicateduplicate |
{a: {b},c}→{a: {b}} in {{ }} | Vue would read the new }} as the end of an interpolationinvalidtemplate-text |
{ get a() {}, … }→{ … } with nine getters | A member such as a getter needs a copy of the object, and the object has more than eightinvalidliteral-copies |
The coarseMutants setting brings back
solitary, and timeouts brings back
loop-advance; strict turns on both. solitary also comes back when the
mutant inside doesn’t run, for example because its mutator is off. The other
changes stay skipped.