nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.55k stars 29.58k forks source link

Node jest not able to identify function #25453

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hello there,

I am trying to create a simple Hash using SHA256. While testing it, I am getting following error:

TypeError: cryptoHash is not a function

at Object. () at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16) at bootstrap_node.js:612:3

**Here is my code:

crypto-hash.js**

`const crypto = require("crypto");

const cryptoHash = (...inputs) => { const hash = crypto.createHash("sha256"); hash.update(inputs.sort().join(" ")); return hash.digest("hex"); };

module.export = cryptoHash; `

Testcase:

crypto-hash.test.js

`const cryptoHash = require("./crypto-hash");

describe("cryptoHash()", () => { it("produces same hash with same input in any order", () => { expect(cryptoHash("one", "two", "three")).toEqual( cryptoHash("three", "one", "two") ); }); }); `

My versions of node and npm:

**npm -v 6.5.0

node -v v8.11.3**

Regards, Arindam

mscdex commented 5 years ago

This issue tracker is for reporting bugs in node core and submitting feature requests for node core.

General help questions should be posted to the nodejs/help issue tracker instead.

Issues with third-party modules, npm, or other tools that use node, should be posted to the appropriate issue tracker for that project, unless it can be proven that the issue is in fact with node core and not the module/tool in question.