#testing 16 articles
global.navigator = dom.window.navigator is ignored on Node 21+ (or throws) — your jsdom test runs with Node's navigator gotchas / tooling Node 21 added a global navigator that has a getter and no setter, so the classic hand-made jsdom setup line is silently ignored (strict mode throws a TypeError) and the test sees Node's userAgent (e.g. "Node.js/24")… TextEncoder is not defined before your first test runs — a dependency needs it at import time and jsdom does not have it gotchas / tooling jsdom has no Encoding API and a dependency that builds new TextEncoder() at module level dies on import, before beforeAll; import a polyfill module first or use setupFiles, and make the dependency lazy A $filter literal encoded twice finds nothing — with a 200 gotchas / rest-api If a helper already percent-encodes the quoted literal, wrapping the whole $filter in encodeURIComponent encodes the value a second time (/ → %252F, @ → %2540); SharePoint then compares against the escaped text and… A component from a linked package throws "Invalid hook call" in Jest — the test loaded a second copy of React gotchas / tooling Jest resolves a file:/junction package by its real path, so the package's require('react') finds a second copy; map react and react-dom to the app's copy (the SPFx build is unaffected — React is a platform component) A deleted or moved test keeps running from stale lib-commonjs — the SPFx rig's --clean never touches that folder gotchas / spfx In SPFx projects built with Heft, Jest runs the compiled tests in lib-commonjs, but the rig's clean step deletes dist, lib, release, generated .scss.ts/.resx.ts files and parts of temp (and jest-output for the test… A Promise wrapped around img.onload can hang forever — try/catch won't save you gotchas / spfx onload/onerror are not guaranteed to fire; try/catch guards rejection, not a Promise that never settles A status code measures where the request stopped first, not what the user may do gotchas / permissions A probe that writes with a deliberately stale IF-MATCH and reads permissions off 403 vs 412 measures which gate the request hit first: SharePoint evaluates the etag BEFORE authorisation, so 412 comes back even where… A test that plants a git hook without chmod passes on Windows and fails on Linux CI gotchas / tooling Git ignores a hook without the executable bit, but Git for Windows does not check that bit and runs a hook that starts with #!/bin/sh, so a fixture that writes .git/hooks/pre-commit with writeFileSync blocks the commit… A test that runs under a different command than your release guards nothing gotchas / spfx heft build runs no Jest and the two prebuild scripts drift, so a rule can look covered while never executing on the release path Hand-built .docx / .pptx: the parts Office demands even though they do nothing gotchas / spfx Header images are referenced from the header's own rels, Content_Types must know the image extension, namespaces are per part, and a .pptx without theme + master + layout is invalid; split parts from zipping so a… In a Heft/SPFx project jest.mock() doesn't hoist — and sp-http drags in a missing MS-internal module gotchas / spfx Tests run over pre-compiled lib-commonjs without Babel, so a mock written below the imports lands after require; write it above the imports or use moduleNameMapper (and why only some sp-http suites die on… Jest's 5-second default timeout fails render tests under load, and the timed-out test breaks the next one gotchas / tooling The first jsdom + React test of a suite pays for the cold module load; on a busy build machine it passes 5 s, Jest abandons it while its async render keeps running, and the following test fails with "button not found"… pdf-parse and pdfjs-dist cannot share a Node process — "bad XRef entry" on classic PDFs gotchas / azure-functions Loading pdfjs-dist breaks pdf-parse's bundled pdf.js 1.10 ("bad XRef entry"), but only for classic xref-table PDFs and from the second request on — one PDF library per process; plus: load code under test with the… Setting process.env.TZ inside Jest does not change the time zone gotchas / tooling A test, setupFiles and setupFilesAfterEnv write into the sandbox's copy of process.env, so day-boundary tests pass only on machines already in the right zone; pin it in globalSetup, assert the offset, and run once… The hosted workbench restores your web parts on the next site you open in the same tab gotchas / spfx The hosted workbench keeps its canvas in sessionStorage per tenant origin, not per site; open another site's workbench in the same tab and your web part boots there — with that site's pageContext, so first-run… Verifying CORS by header presence passes every origin — compare the value to the Origin you sent gotchas / azure-functions The header comes back for every origin (servers answer with a fallback, not an omission), so presence proves nothing; compare it to the Origin you sent, keep at least one case that expects allowed, and point the probe…