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

Child objects of a mocked instance can't access their own private fields #151

Open
mchalapuk opened this issue Dec 13, 2023 · 0 comments
Open

Comments

@mchalapuk
Copy link

mchalapuk commented Dec 13, 2023

Hi, I seem to be having a bit of a problem with mocked instances that have child objects that use private fields.

A short piece of code replicating the issue:

import test from "ava"
import { Mock } from "typemoq"
import * as crypto from "crypto"

class UUID {
  #uuid: string

  constructor(uuid: string = crypto.randomUUID()) {
    this.#uuid = uuid
  }
  toString() {
    return this.#uuid
  }
}

test("test mock with a private field in a child object", t => {
  const uuid = new UUID()
  t.assert(uuid.toString(), uuid.toString()) // this works

  const mock = Mock.ofInstance({ uuid })
  mock.object.uuid.toString() // this throws an error
})

The error I'm getting is the following:
Screenshot 2023-12-13 at 02 33 17

I think it has something to do with how proxies are used in typemoq.

If I'm missing something, I'd appreciate if someone could direct me to a solution. Otherwise, it seems to be a big problem which needs solving. I'm happy to work on it and create a PR but I would need some direction on how to solve it.

Thanks.

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