isObject helper fails in jest
See original GitHub issueDescribe the bug
fromKeyLike
does not return an object (JWK). If you use the output of this function in the latest version of node you get the following error:
TypeError: JWK must be an object
To Reproduce
Use Node v15.14.0.
const key = crypto.generateKeyPairSync("ec", {
namedCurve: "secp256k1",
});
const privateJwk = await fromKeyLike(key.privateKey);
// ^^^^^^^^^^ this is not an object
const privateKey = await parseJwk(privateJwk, "ES256K");
// TypeError: JWK must be an object
Expected behaviour Get proper object so as to be able to use JWK.
Environment:
jose
version: 3.11.4- Typescript v4.2.4
- affected runtime is: Node.js v15.14.0
Additional context If anyone faces the same issue, there are two tricks that can save you:
- Do not use
privateJwk
in the next function as input but{...privateJwk }
or - After getting
privateJwk
setjwk.constructor = Object;
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Using Matchers - Jest
In this code, .toBe(4) is the matcher. When Jest runs, it tracks all the failing matchers so that it can print out nice...
Read more >How to assert data type with Jest - node.js - Stack Overflow
Use instanceof to prove whether the result variable is a Date Object or Not. Example: expect(result instanceof Date).
Read more >Helper Functions for Assertions (Jest & Node.js)
isObjectPropertyEmpty.helper"); describe("isObjectPropertyEmpty helper function unit tests", () => { it("should validate incoming module ...
Read more >Object.defineProperty() - JavaScript - MDN Web Docs
throws an error in strict mode ... trying to write into the non-writable property doesn't change it but doesn't throw an error either....
Read more >Jest Expect - w3resource
If differences between properties do not help you to understand why a test failed, especially for large report, then you can move the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Alright. I’ve updated the gist I shared with you. Now you should be able to clone it and run:
You’ll see that the test fails for this node version but not for older. Notice that to make this test pass in my project I fix it with the trick found in
AuxTest.ts
, swtiching how I return JWK:@maurolucc that is of no help unfortunately. I have no clue what the package.json looks like, how you execute this, nor what the typescript configuration is.
I’m looking for a reproduction, e.g. such as that i can clone the gist, run
npm i
and then execute whatever command that reproduces the issue.