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

t.assert is not a function #53449

Closed
Quramy opened this issue Jun 14, 2024 · 5 comments
Closed

t.assert is not a function #53449

Quramy opened this issue Jun 14, 2024 · 5 comments
Labels
question Issues that look for answers. test_runner Issues and PRs related to the test runner subsystem.

Comments

@Quramy
Copy link

Quramy commented Jun 14, 2024

Version

v22.3.0

Platform

Darwin CF0393.local 21.6.0 Darwin Kernel Version 21.6.0: Thu Sep 29 20:13:56 PDT 2022; root:xnu-8020.240.7~1/RELEASE_ARM64_T6000 arm64

Subsystem

test_runner

What steps will reproduce the bug?

/* assert.js */

import assert from "node:assert";
import { test } from "node:test";

test("context assert", (t) => {
  t.assert(true);
});

test("assert module", (t) => {
  assert(true);
});
node --test assert.js

✖ context assert (0.720083ms)
  TypeError [Error]: t.assert is not a function
      at TestContext.<anonymous>
      at Test.runInAsyncScope (node:async_hooks:206:9)
      at Test.run (node:internal/test_runner/test:856:25)
      at Test.processPendingSubtests (node:internal/test_runner/test:565:18)
      at node:internal/test_runner/harness:248:12
      at node:internal/process/task_queues:140:7
      at AsyncResource.runInAsyncScope (node:async_hooks:206:9)
      at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)

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

No response

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

t.assert can be called as a function.

What do you see instead?

✖ context assert (0.720083ms)
  TypeError [Error]: t.assert is not a function

Additional information

I read about context.assert of Test runner:

https://nodejs.org/docs/latest/api/test.html#contextassert

And this doc says the following:

The top-level functions from the node:assert module are exposed here

Is this difference intended ? (I feel it lacked consistency)

@climba03003
Copy link
Contributor

climba03003 commented Jun 14, 2024

I believe it means the functions inside assert is exposed instead of mirroring the whole assert.

@MoLow MoLow added the test_runner Issues and PRs related to the test runner subsystem. label Jun 14, 2024
@Quramy
Copy link
Author

Quramy commented Jun 14, 2024

If you are not intentionally exposing t.assert(), you may close this issue.

@RedYetiDev
Copy link
Member

RedYetiDev commented Jun 14, 2024

An object containing assertion methods bound to context. The top-level functions from the node:assert module are exposed here for the purpose of creating test plans.

t.assert isn't a function, but an object, try logging it in the console to see what it can do

(As previously stated by @climba03003)

@RedYetiDev RedYetiDev added question Issues that look for answers. assert Issues and PRs related to the assert subsystem. labels Jun 14, 2024
@cjihrig cjihrig removed the assert Issues and PRs related to the assert subsystem. label Jun 14, 2024
@cjihrig
Copy link
Contributor

cjihrig commented Jun 14, 2024

I can confirm that it was not my plan for the t.assert object to be the assert() function. Whether that is something we want to support or not - I don't have an opinion either way, as long as it is implemented in a way that the t.assert function could be changed in the future programmatically. I would still like to add an API for decoupling t.assert from the assert module (snapshot tests were the proof of concept for that).

@RedYetiDev RedYetiDev closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2024
@Quramy
Copy link
Author

Quramy commented Jun 14, 2024

@cjihrig

I can confirm that it was not my plan for the t.assert object to be the assert() function.

Thanks for your answer !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants
@Quramy @cjihrig @MoLow @climba03003 @RedYetiDev and others