PageSourceSearch

https://pester.dev/assets/js/ac0c8ac6.6ca2e4a5.js

js pester.dev collected 2026-10-03 19:38:06 UTC 4,899 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkpester_docs=self.webpackChunkpester_docs||[]).push([["3719"],{505(e,t,s){s.r(t),s.d(t,{metadata:()=>i,default:()=>h,frontMatter:()=>a,contentTitle:()=>l,toc:()=>d,assets:()=>o});var i=JSON.parse('{"id":"usage/testregistry","title":"Isolating Windows Registry Operations using the TestRegistry","description":"TestRegistry is a PowerShell PSDrive (Windows only) to help your store temporary values used in your tests in the Windows Registry that are automatically cleaned up after your tests are finished","source":"@site/docs/usage/testregistry.mdx","sourceDirName":"usage","slug":"/usage/testregistry","permalink":"/docs/usage/testregistry","draft":false,"unlisted":false,"editUrl":"https://github.com/pester/docs/edit/main/docs/usage/testregistry.mdx","tags":[],"version":"current","frontMatter":{"id":"testregistry","title":"Isolating Windows Registry Operations using the TestRegistry","sidebar_label":"TestRegistry","description":"TestRegistry is a PowerShell PSDrive (Windows only) to help your store temporary values used in your tests in the Windows Registry that are automatically cleaned up after your tests are finished"},"sidebar":"docs","previous":{"title":"TestDrive","permalink":"/docs/usage/testdrive"},"next":{"title":"Test Results","permalink":"/docs/usage/test-results"}}'),r=s(1987),n=s(7008);let a={id:"testregistry",title:"Isolating Windows Registry Operations using the TestRegistry",sidebar_label:"TestRegistry",description:"TestRegistry is a PowerShell PSDrive (Windows only) to help your store temporary values used in your tests in the Windows Registry that are automatically cleaned up after your tests are finished"},l,o={},d=[{value:"Scoping",id:"scoping",level:2},{value:"Example",id:"example",level:2}];function c(e){let t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",...(0,n.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.p,{children:"TestRegistry is a Windows-only PowerShell PSDrive used to isolate registry based tests."}),"\n",(0,r.jsxs)(t.p,{children:["Pester creates a temporary, randomly named, registry key in the current user's hive under ",(0,r.jsx)(t.code,{children:"HKCU:\\Software\\Pester"})," which is accessible as ",(0,r.jsx)(t.code,{children:"TestRegistry:"}),"."]}),"\n",(0,r.jsx)(t.h2,{id:"scoping",children:"Scoping"}),"\n",(0,r.jsxs)(t.p,{children:["Basic scoping rules are implemented for the TestRegistry in a similar way to ",(0,r.jsx)(t.a,{href:"./testdrive",children:"TestDrive"}),":"]}),"\n",(0,r.jsxs)(t.ol,{children:["\n",(0,r.jsx)(t.li,{children:"A clean TestRegistry is created per container (test-file or scriptblock) on entry to the first top-level block (Describe or Context) in that container."}),"\n",(0,r.jsx)(t.li,{children:"All keys and values created by your setups and tests are available during the lifetime of that block, including inner blocks and tests."}),"\n",(0,r.jsxs)(t.li,{children:["All ",(0,r.jsx)(t.strong,{children:"keys"})," are removed when exiting the block they were created in. Keys created in parent blocks is kept until that block is finished."]}),"\n",(0,r.jsx)(t.li,{children:"When the whole container is finished, the temporary registry key is deleted and all the subkeys and values with it."}),"\n"]}),"\n",(0,r.jsx)(t.admonition,{title:"Cleanup is done at key-level",type:"note",children:(0,r.jsx)(t.p,{children:"Be aware that cleanup in TestRegistry currently works on registry key-level. Values created inside an existing key from the parent block will persist until the key itself is deleted when the parent block is finished."})}),"\n",(0,r.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-powershell",children:'BeforeAll {\n    function Get-InstallPath($path, $key) {\n        Get-ItemProperty -Path $path -Name $key | Select-Object -ExpandProperty $key\n    }\n}\n\nDescribe "Get-InstallPath" {\n    BeforeAll {\n        New-Item -Path TestRegistry:\\ -Name TestLocation\n        New-ItemProperty -Path "TestRegistry:\\TestLocation" -Name "InstallPath" -Value "C:\\Program Files\\MyApplication"\n    }\n\n    It \'reads the install path from the registry\' {\n        Get-InstallPath -Path "TestRegistry:\\TestLocation" -Key "InstallPath" | Should-Be "C:\\Program Files\\MyApplication"\n    }\n}\n'})})]})}function h(e={}){let{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},7008(e,t,s){s.d(t,{R:()=>a,x:()=>l});var i=s(1763);let r={},n=i.createContext(r);function a(e){let t=i.useContext(n);return i.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),i.createElement(n.Provider,{value:t},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.