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

bug: error exception after instance custom promise (with jsdom) #3281

Closed
6 tasks done
hairyf opened this issue May 2, 2023 · 3 comments · Fixed by #3298
Closed
6 tasks done

bug: error exception after instance custom promise (with jsdom) #3281

hairyf opened this issue May 2, 2023 · 3 comments · Fixed by #3298

Comments

@hairyf
Copy link

hairyf commented May 2, 2023

Describe the bug

  // 1. create promise
  let resolve, reject;
  const promise = new Promise((_resolve, _reject) => {
    resolve = _resolve;
    reject = _reject;
  }) as any;
  // add any attributes to promise
  promise.a = 1;
  promise.resolve = resolve;
  promise.reject = reject;

  // 2. use promise callback
  promise.finally(() => {
    console.log('---');
  });

  // TypeError: Cannot create property 'type' on string 'manual-reject'
  expect(promise).rejects.toBe('manual-reject');

  // reject promise
  reject('manual-reject');

image

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-og7ted?file=test%2Fbasic.test.ts,vite.config.ts,package.json&initialPath=__vitest__

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor
    Memory: 1.49 GB / 15.93 GB
  Binaries:
    Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.5.5 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @vitejs/plugin-react: ^4.0.0 => 4.0.0 
    @vitejs/plugin-vue: ^4.0.0 => 4.0.0 
    @vitest/coverage-c8: ^0.29.2 => 0.29.2 
    vite: ^4.2.0 => 4.2.0 
    vitest: ^0.30.1 => 0.30.1

Used Package Manager

pnpm

Validations

@stackblitz
Copy link

stackblitz bot commented May 2, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sheremet-va
Copy link
Member

You need to await expect if you pass a promise (use rejects/resolves)

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale May 2, 2023
@sheremet-va sheremet-va reopened this May 2, 2023
@sheremet-va
Copy link
Member

sheremet-va commented May 2, 2023

I see now another issue with your repro (Vitest thinks a string is an object), thanks.

@hairyf hairyf changed the title bug: error exception after instance after custom promise (with jsdom) bug: error exception after instance custom promise (with jsdom) May 3, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jun 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants