Skip to content

object.filter'd objects fail strictEquals checks with normal object #99

@jmoses

Description

@jmoses

If you filter an object, and try to strictEqual it with a POJO with the filtered fields, the assertion fails.

import {expect} from '@playwright/test'
import stdlib  from '@logdna/stdlib'

const o = {
    field: 'val'
    , field2: 'val2'
}

const e = {field: 'val'}
const f = stdlib.object.filter(o, (k) => k !== 'field2')

console.log(e)
console.log(f)

expect(e).toStrictEqual(f)

I'm not sure where playwright gets it's expect library from, and couldn't find out with a few minutes of searching.

> node fail.js
{ field: 'val' }
[Object: null prototype] { field: 'val' }
/Users/jmoses/dev/logdna/qa-e2e-pipeline/node_modules/@playwright/test/lib/matchers/expect.js:131
      if (!testInfo) return matcher.call(target, ...args);
                                    ^

Ze [Error]: expect(received).toStrictEqual(expected) // deep equality

Expected: {"field": "val"}
Received: serializes to the same string
    at Proxy.<anonymous> (/Users/jmoses/dev/logdna/qa-e2e-pipeline/node_modules/@playwright/test/lib/matchers/expect.js:131:37)
    at file:///Users/jmoses/dev/logdna/qa-e2e-pipeline/fail.js:15:11
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at loadESM (node:internal/process/esm_loader:88:5)
    at handleMainPromise (node:internal/modules/run_main:61:12) {
  matcherResult: {
    actual: { field: 'val' },
    expected: [Object: null prototype] { field: 'val' },
    message: '\x1B[2mexpect(\x1B[22m\x1B[31mreceived\x1B[39m\x1B[2m).\x1B[22mtoStrictEqual\x1B[2m(\x1B[22m\x1B[32mexpected\x1B[39m\x1B[2m) // deep equality\x1B[22m\n' +
      '\n' +
      'Expected: \x1B[32m{"field": "val"}\x1B[39m\n' +
      'Received: serializes to the same string',
    name: 'toStrictEqual',
    pass: false
  }
}
> npm list | grep -E 'playwright/test|logdna/stdlib'
├── @logdna/stdlib@1.2.0
├── @playwright/test@1.32.1

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