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

Should be able to compare equality of circular structures #5

Open
axelpale opened this issue Dec 15, 2022 · 0 comments
Open

Should be able to compare equality of circular structures #5

axelpale opened this issue Dec 15, 2022 · 0 comments

Comments

@axelpale
Copy link

axelpale commented Dec 15, 2022

Problem: I have a tape test that compares strict equality of two objects. These objects have circular structure by design. If the test fails because the objects are not equal, tape-dom seems to be unable to render those objects and TypeError is thrown (see below). The JSON.stringify call is the source of the error.

Context: I have a tape test suite, which is bundled with webpack, and then ran in browser. I want to use tape-dom to render the test results on the page instead of console, in order to avoid opening the dev console every time. This worked fine until the problem above arose. I could bypass the problem by comparing some non-circular properties of those objects, but I feel it should not be necessary here in the case of strict equality comparison ===. Such bypass would probably be the best option for deepEqual assertions but not for strict.

Possible solution 1: in dom_consumer.js, catch TypeError, do not render the objects if they are problematic, and continue with the next assert.

Possible solution 2: in dom_consumer.js, replace JSON.stringify with a renderer that is able to handle circular structures. For example flatted might be a good candidate. See also this StackOverflow page for alternatives: https://stackoverflow.com/questions/11616630/how-can-i-print-a-circular-structure-in-a-json-like-format

Here is the error:

Uncaught TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'HTMLDivElement'
    |     property 'affine' -> object with constructor 'Item'
    --- property 'element' closes the circle
    at JSON.stringify (<anonymous>)
    at assertFailDiv (dom_consumer.js?6fa6:83:1)
    at Stream.add_some_dom (dom_consumer.js?6fa6:137:1)
    at Stream.emit (events.js?8416:153:1)
    at drain (index.js?e6f0:36:1)
    at stream.queue.stream.push (index.js?e6f0:45:1)
    at Stream.write (index.js?e6f0:14:38)
    at stream.write (index.js?e6f0:26:1)
    at Stream.ondata (index.js?646e:53:1)
    at Stream.emit (events.js?8416:153:1)

And finally, thanks for the package and any upcoming work and considerations regarding the issue.

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