Skip to content

Instantly share code, notes, and snippets.

@dantman
Created June 15, 2022 04:42
Show Gist options
  • Save dantman/a2425f88f6c5cb167061c843bd54f373 to your computer and use it in GitHub Desktop.
Save dantman/a2425f88f6c5cb167061c843bd54f373 to your computer and use it in GitHub Desktop.
Test Page for of ES modules usage with nullish coalescing

Test Page for of ES modules usage with nullish coalescing

TestCafe's proxy breaks nullish coalescing. This is a basic demo using the syntax for a test case.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Page for of ES modules usage with nullish coalescing</title>
</head>
<body>
<h1>Test Page for of ES modules usage with nullish coalescing</h1>
<p>TestCafe's proxy breaks nullish coalescing. This is a basic demo using the syntax for a test case.</p>
<p>The error will only show up in the console when run through TestCafe.</p>
<p>Result: <span id="result">Script not completed</span></p>
<script type="module">
import './index.js'
</script>
</body>
</html>
// Variables
const a = undefined;
const b = 'b';
const c = 0;
const get = () => 1;
const obj = {b: 1}
// Normal nullish colascing usage
const d = a ?? b;
// nullish colascing with parentheses
const e = (a && b) ?? c;
// nullish colascing with a function
const f = get() ?? c;
// nullish colascing with a function and parentheses
const g = (a && get()) ?? c;
// nullish colascing with property syntax
const h = obj['b'] ?? c;
// nullish colascing with property syntax and parentheses
const i = (a && obj['b']) ?? c;
// nullish colascing with dynamic property syntax
const j = obj[b] ?? c;
// nullish colascing with dynamic property syntax and parentheses
const k = {a: (b && obj[b]) ?? c};
// nullish colascing with dynamic property syntax, parentheses, and descructuring
const {l} = {l: (b && obj[b]) ?? c};
// Test completed
document.getElementById('result').innerHTML = 'Script completed';
export {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment