How to use printBigInt method in Jest

Best JavaScript code snippet using jest

Run Jest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

literal.js

Source: literal.js Github

copy
1"use strict";
2const { printString, printNumber } = require("../../common/util");
3
4function printLiteral(path, options /*, print*/) {
5  const node = path.getNode();
6
7  switch (node.type) {
8    case "RegExpLiteral": // Babel 6 Literal split
9      return printRegex(node);
10    case "BigIntLiteral":
11      // babel: node.extra.raw, flow: node.bigint
12      return printBigInt(node.bigint || node.extra.raw);
13    case "NumericLiteral": // Babel 6 Literal split
14      return printNumber(node.extra.raw);
15    case "StringLiteral": // Babel 6 Literal split
16      return printString(node.extra.raw, options);
17    case "NullLiteral": // Babel 6 Literal split
18      return "null";
19    case "BooleanLiteral": // Babel 6 Literal split
20      return String(node.value);
21    case "DecimalLiteral":
22      return printNumber(node.value) + "m";
23    case "Literal": {
24      if (node.regex) {
25        return printRegex(node.regex);
26      }
27
28      if (node.bigint) {
29        return printBigInt(node.raw);
30      }
31
32      const { value } = node;
33
34      if (typeof value === "number") {
35        return printNumber(node.raw);
36      }
37
38      if (typeof value === "string") {
39        return printString(node.raw, options);
40      }
41
42      return String(value);
43    }
44  }
45}
46
47function printBigInt(raw) {
48  return raw.toLowerCase();
49}
50
51function printRegex({ pattern, flags }) {
52  flags = flags.split("").sort().join("");
53  return `/${pattern}/${flags}`;
54}
55
56module.exports = {
57  printLiteral,
58};
59
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Jest on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)