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 destructuring + rest doesn't work #129

Open
0xjocke opened this issue Sep 17, 2020 · 3 comments
Open

Object destructuring + rest doesn't work #129

0xjocke opened this issue Sep 17, 2020 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@0xjocke
Copy link

0xjocke commented Sep 17, 2020

Describe the bug
I cant use a Substitute mock for code that uses object destructuring + rest

To Reproduce

import Substitute from "@fluffy-spoon/substitute";

type Entity = { id: number; name: string; lastName: string };

const copyEntity = (entity: Entity) => {
  const { id, ...params } = entity;
  console.log(params);
};

const mockEntity = Substitute.for<Entity>();
mockEntity.id.returns!(1);
mockEntity.name.returns!('test name');
mockEntity.lastName.returns!('test last name');

copyEntity(mockEntity); // empty object
copyEntity({id:1, name: 'test name', lastName: 'test last name'})  // {name: 'test name', lastName: 'test last name'}

Codesandbox:
https://codesandbox.io/s/flamboyant-sea-o5zf4?file=/src/index.ts:0-469

Expected behavior
I should be able to test functions using destructuring with the rest pattern

Environment

  • Typescript version: 3.9.3
  • substitute.js version: 1.145.0
  • Node version: 12
@notanengineercom
Copy link
Collaborator

Thank you for the detailed report!
Can confirm the bug ^^

@ffMathy
Copy link
Owner

ffMathy commented Sep 28, 2020

Maybe the proxy object has a method for destructuring that we're missing.

@notanengineercom
Copy link
Collaborator

Yes, we need to add a trap to handle the spread assignments!

@notanengineercom notanengineercom added the bug Something isn't working label Sep 28, 2020
@ffMathy ffMathy added this to the v2.0 milestone Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants