Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jmoses opened this issue Apr 13, 2023 · 1 comment
Open

Comments

@jmoses
Copy link
Contributor

jmoses commented Apr 13, 2023

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/[email protected]
├── @playwright/[email protected]
@jmoses
Copy link
Contributor Author

jmoses commented Apr 13, 2023

import {expect} from '@playwright/test'
import {omit}  from 'lodash-es'

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

const e = {field: 'val'}
const f = omit(o, ['field2'])

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

expect(e).toStrictEqual(f)

does work as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant