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

libxmljs doesn't work properly under Jest #8636

Closed
frei-0xff opened this issue Jul 3, 2019 · 4 comments
Closed

libxmljs doesn't work properly under Jest #8636

frei-0xff opened this issue Jul 3, 2019 · 4 comments

Comments

@frei-0xff
Copy link

🐛 Bug Report

libxmljs package doesn't work properly when used in Jest test

To Reproduce

Try to run test:

const libxmljs = require('libxmljs')

test('Test libxmljs', () => {
  expect(
    libxmljs
      .parseXml('<customer></customer>')
      .get('/customer')
      .type()
  ).toBe('element')
})

Expected behavior

It's expected to pass, but It's failing with error:

TypeError: libxmljs.parseXml(...).get(...).type is not a function

The same code run by node.js works just fine and returns 'element'

Link to repl or repo

Minimal repository to reproduce bug: https://github.com/frei-0xff/jest-libxmljs-issue

Run npx envinfo --preset jest

  System:
    OS: Windows 10
    CPU: (2) ia32 Intel(R) Core(TM)2 Duo CPU     T7250  @ 2.00GHz
  Binaries:
    Node: 10.15.3 - C:\Program Files\nodejs\node.EXE
    npm: 5.10.0 - C:\Program Files\nodejs\npm.CMD
@frei-0xff
Copy link
Author

frei-0xff commented Jul 3, 2019

As far as I managed to investigate the problem, it comes down to this:
In the following code from libxmljs module this.find is native C++ function which returns Array object

Element.prototype.get = function() {
    var res = this.find.apply(this, arguments);
    if (res instanceof Array) {
        return res[0];
    } else {
        return res;
    }
};

It returns the same Array object when executed by node.js or within jest test,
but operator

res instanceof Array

when executed by bare node.js returns true as it should,
while when executed under jest for some miraculous reason it returns false.

@jeysal
Copy link
Contributor

jeysal commented Jul 3, 2019

Based on your comment about instanceof Array, it's probably caused by #2549

@frei-0xff
Copy link
Author

Yeah, it's definitely caused by #2549
Duplicate issue. Closing.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants