1"use strict";(self.webpackChunkpester_docs=self.webpackChunkpester_docs||[]).push([["3050"],{262(e,t,s){s.r(t),s.d(t,{metadata:()=>r,default:()=>h,frontMatter:()=>a,contentTitle:()=>o,toc:()=>c,assets:()=>l});var r=JSON.parse('{"id":"usage/testregistry","title":"Isolating Windows Registry Operations using the TestRegistry","description":"TestRegistry is a Windows-only PowerShell PSDrive used to isolate registry based tests.","source":"@site/versioned_docs/version-v4/usage/testregistry.mdx","sourceDirName":"usage","slug":"/usage/testregistry","permalink":"/docs/v4/usage/testregistry","draft":false,"unlisted":false,"editUrl":"https://github.com/pester/docs/edit/main/versioned_docs/version-v4/usage/testregistry.mdx","tags":[],"version":"v4","frontMatter":{"id":"testregistry","title":"Isolating Windows Registry Operations using the TestRegistry","sidebar_label":"TestRegistry"},"sidebar":"docs","previous":{"title":"TestDrive","permalink":"/docs/v4/usage/testdrive"},"next":{"title":"Test Results","permalink":"/docs/v4/usage/test-results"}}'),i=s(1987),n=s(7008);let a={id:"testregistry",title:"Isolating Windows Registry Operations using the TestRegistry",sidebar_label:"TestRegistry"},o,l={},c=[{value:"Scoping",id:"scoping",level:2},{value:"Example",id:"example",level:2}];function d(e){let t={a:"a",code:"code",h2:"h2",p:"p",pre:"pre",...(0,n.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.p,{children:"TestRegistry is a Windows-only PowerShell PSDrive used to isolate registry based tests."}),"\n",(0,i.jsxs)(t.p,{children:["Pester creates a temporary, randomly named (a guid), registry key in the current user's hive under ",(0,i.jsx)(t.code,{children:"HKCU:\\Software\\Pester"})," which is accessible as ",(0,i.jsx)(t.code,{children:"TestRegistry:"}),"."]}),"\n",(0,i.jsx)(t.h2,{id:"scoping",children:"Scoping"}),"\n",(0,i.jsxs)(t.p,{children:["Basic scoping rules are implemented for the TestRegistry in a similar way to ",(0,i.jsx)(t.a,{href:"./testdrive",children:"TestDrive"}),". A clean TestRegistry is created on entry to every Describe block and all the keys and values created by your tests are available during the lifetime of that Describe scope. One important difference from ",(0,i.jsx)(t.a,{href:"./testdrive",children:"TestDrive"})," is that registry keys and values persist within the Describe block and any changes to the registry in the scope of an It or Context block remain until the scope of the Describe block ends. When the Describe block is finished the temporary registry key is deleted and all the subkeys and values with it."]}),"\n",(0,i.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-powershell",children:'Function Get-InstallPath($path, $key) {\n Get-ItemProperty -Path $path -Name $key | Select-Object -ExpandProperty $key\n}\n\nDescribe "Get-InstallPath" {\n\n New-Item -Path TestRegistry:\\ -Name TestLocation\n New-ItemProperty -Path "TestRegistry:\\TestLocation" -Name "InstallPath" -Value "C:\\Program Files\\MyApplication"\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,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},7008(e,t,s){s.d(t,{R:()=>a,x:()=>o});var r=s(1763);let i={},n=r.createContext(i);function a(e){let t=r.useContext(n);return r.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),r.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.