Skip to content

assert.deepEqual() report difference between promises during test #55198

Open
@regseb

Description

@regseb

Version

v22.9.0

Platform

Linux regseblaptop 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

Ubuntu 24.04.1 LTS

What steps will reproduce the bug?

  1. Create test.mjs
import assert from "node:assert/strict";
import { mock, test } from "node:test";

test("promise", () => {
    assert.deepEqual(Promise.resolve("foo"), Promise.resolve("foo"));
});

test("mock, promise and await", async () => {
    const fn = mock.fn(() => "foo");
    await fn(Promise.resolve("bar"));
    assert.deepEqual(fn.mock.calls[0].arguments[0], Promise.resolve("bar"));
});
  1. node --test test.mjs

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

The assert.deepEqual() doesn't report difference between the two identical promises.

✔ promise (1.830551ms)
✔ mock, promise and await (0.533274ms)
ℹ tests 2
ℹ suites 0
ℹ pass 2
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 75.905452

What do you see instead?

The assert.deepEqual() find difference between the two identical promises.

✖ promise (5.761508ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
  + actual - expected
  
    Promise {
      'foo',
  +   [Symbol(async_id_symbol)]: 39,
  -   [Symbol(async_id_symbol)]: 40,
      [Symbol(trigger_async_id_symbol)]: 17
    }
      at TestContext.<anonymous> (file:///home/regseb/dev/tc/mock/test.mjs:5:12)
      at Test.runInAsyncScope (node:async_hooks:211:14)
      at Test.run (node:internal/test_runner/test:930:25)
      at Test.start (node:internal/test_runner/test:829:17)
      at startSubtestAfterBootstrap (node:internal/test_runner/harness:289:17) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: [Promise],
    expected: [Promise],
    operator: 'deepStrictEqual'
  }

✖ mock, promise and await (0.791194ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
  + actual - expected
  
    Promise {
      'bar',
  +   [Symbol(async_id_symbol)]: 52,
  +   [Symbol(trigger_async_id_symbol)]: 20
  -   [Symbol(async_id_symbol)]: 66,
  -   [Symbol(trigger_async_id_symbol)]: 54
    }
      at TestContext.<anonymous> (file:///home/regseb/dev/tc/mock/test.mjs:11:12)
      at async Test.run (node:internal/test_runner/test:931:9)
      at async Test.processPendingSubtests (node:internal/test_runner/test:629:7) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: [Promise],
    expected: [Promise],
    operator: 'deepStrictEqual'
  }

ℹ tests 2
ℹ suites 0
ℹ pass 0
ℹ fail 2
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 82.541815

✖ failing tests:

test at test.mjs:4:1
✖ promise (5.761508ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
  + actual - expected
  
    Promise {
      'foo',
  +   [Symbol(async_id_symbol)]: 39,
  -   [Symbol(async_id_symbol)]: 40,
      [Symbol(trigger_async_id_symbol)]: 17
    }
      at TestContext.<anonymous> (file:///home/regseb/dev/tc/mock/test.mjs:5:12)
      at Test.runInAsyncScope (node:async_hooks:211:14)
      at Test.run (node:internal/test_runner/test:930:25)
      at Test.start (node:internal/test_runner/test:829:17)
      at startSubtestAfterBootstrap (node:internal/test_runner/harness:289:17) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: [Promise],
    expected: [Promise],
    operator: 'deepStrictEqual'
  }

test at test.mjs:8:1
✖ mock, promise and await (0.791194ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
  + actual - expected
  
    Promise {
      'bar',
  +   [Symbol(async_id_symbol)]: 52,
  +   [Symbol(trigger_async_id_symbol)]: 20
  -   [Symbol(async_id_symbol)]: 66,
  -   [Symbol(trigger_async_id_symbol)]: 54
    }
      at TestContext.<anonymous> (file:///home/regseb/dev/tc/mock/test.mjs:11:12)
      at async Test.run (node:internal/test_runner/test:931:9)
      at async Test.processPendingSubtests (node:internal/test_runner/test:629:7) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: [Promise],
    expected: [Promise],
    operator: 'deepStrictEqual'
  }

Additional information

The problem only occurs in test. #55198 (comment)

  1. Create index.mjs
import assert from "node:assert/strict";
import { mock } from "node:test";

assert.deepEqual(Promise.resolve("foo"), Promise.resolve("foo"));

const fn = mock.fn(() => "foo");
await fn(Promise.resolve("bar"));
assert.deepEqual(fn.mock.calls[0].arguments[0], Promise.resolve("bar"));
  1. node index.mjs
  2. The assert.deepEqual() doesn't report difference between the two identical promises. 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    assertIssues and PRs related to the assert subsystem.promisesIssues and PRs related to ECMAScript promises.test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions