1"use strict";(self.webpackChunkpester_docs=self.webpackChunkpester_docs||[]).push([["4954"],{7503(e,n,o){o.r(n),o.d(n,{metadata:()=>t,default:()=>u,frontMatter:()=>i,contentTitle:()=>r,toc:()=>c,assets:()=>a});var t=JSON.parse('{"id":"commands/InModuleScope","title":"InModuleScope","description":"Help for Pester command \'InModuleScope\'. Allows you to execute parts of a test script within the scope of a PowerShell script module.","source":"@site/versioned_docs/version-v4/commands/InModuleScope.mdx","sourceDirName":"commands","slug":"/commands/InModuleScope","permalink":"/docs/v4/commands/InModuleScope","draft":false,"unlisted":false,"editUrl":null,"tags":[],"version":"v4","frontMatter":{"id":"InModuleScope","title":"InModuleScope","description":"Help for Pester command \'InModuleScope\'. Allows you to execute parts of a test script within the scope of a PowerShell script module.","keywords":["PowerShell","Pester","Help","Documentation"],"hide_title":false,"hide_table_of_contents":false,"custom_edit_url":null},"sidebar":"commands","previous":{"title":"In","permalink":"/docs/v4/commands/In"},"next":{"title":"Invoke-Gherkin","permalink":"/docs/v4/commands/Invoke-Gherkin"}}'),l=o(1987),s=o(7008);let i={id:"InModuleScope",title:"InModuleScope",description:"Help for Pester command 'InModuleScope'. Allows you to execute parts of a test script within the scope of a PowerShell script module.",keywords:["PowerShell","Pester","Help","Documentation"],hide_title:!1,hide_table_of_contents:!1,custom_edit_url:null},r,a={},c=[{value:"SYNOPSIS",id:"synopsis",level:2},{value:"SYNTAX",id:"syntax",level:2},{value:"DESCRIPTION",id:"description",level:2},{value:"EXAMPLES",id:"examples",level:2},{value:"EXAMPLE 1",id:"example-1",level:3},{value:"PARAMETERS",id:"parameters",level:2},{value:"-ModuleName",id:"-modulename",level:3},{value:"-ScriptBlock",id:"-scriptblock",level:3},{value:"CommonParameters",id:"commonparameters",level:3},{value:"INPUTS",id:"inputs",level:2},{value:"OUTPUTS",id:"outputs",level:2},{value:"NOTES",id:"notes",level:2},{value:"RELATED LINKS",id:"related-links",level:2},{value:"VERSION",id:"version",level:2}];function d(e){let n={a:"a",admonition:"admonition",code:"code",em:"em",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(n.admonition,{title:"This page was generated",type:"info",children:(0,l.jsxs)(n.p,{children:["Contributions are welcome in ",(0,l.jsx)(n.a,{href:"https://github.com/pester/Pester/tree/rel/4.x.x",children:"Pester v4-repo"}),"."]})}),"\n",(0,l.jsx)(n.h2,{id:"synopsis",children:"SYNOPSIS"}),"\n",(0,l.jsx)(n.p,{children:"Allows you to execute parts of a test script within the\nscope of a PowerShell script module."}),"\n",(0,l.jsx)(n.h2,{id:"syntax",children:"SYNTAX"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-powershell",children:"InModuleScope [-ModuleName] <string> [-ScriptBlock] <scriptblock>\n"})}),"\n",(0,l.jsx)(n.h2,{id:"description",children:"DESCRIPTION"}),"\n",(0,l.jsx)(n.p,{children:"By injecting some test code into the scope of a PowerShell\nscript module, you can use non-exported functions, aliases\nand variables inside that module, to perform unit tests on\nits internal implementation."}),"\n",(0,l.jsx)(n.p,{children:"InModuleScope may be used anywhere inside a Pester script,\neither inside or outside a Describe block."}),"\n",(0,l.jsx)(n.h2,{id:"examples",children:"EXAMPLES"}),"\n",(0,l.jsx)(n.h3,{id:"example-1",children:"EXAMPLE 1"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-powershell",children:"# The script module:\nfunction PublicFunction\n{\n # Does something\n}\n\nfunction PrivateFunction\n{\n return $true\n}\n\nExport-ModuleMember -Function PublicFunction\n\n# The test script:\n\nImport-Module MyModule\n\nInModuleScope MyModule {\n Describe 'Testing MyModule' {\n It 'Tests the Private function' {\n PrivateFunction | Should -Be $true\n }\n }\n}\n"})}),"\n",(0,l.jsx)(n.p,{children:'Normally you would not be able to access "PrivateFunction" from\nthe PowerShell session, because the module only exported\n"PublicFunction".\nUsing InModuleScope allowed this call to\n"PrivateFunction" to work successfully.'}),"\n",(0,l.jsx)(n.h2,{id:"parameters",children:"PARAMETERS"}),"\n",(0,l.jsx)(n.h3,{id:"-modulename",children:"-ModuleName"}),"\n",(0,l.jsx)(n.p,{children:"The name of the module into which the test code should be\ninjected.\nThis module must already be loaded into the current\nPowerShell session."}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-yaml",children:"Type: System.String\nDefaultValue: ''\nSupportsWildcards: false\nAliases: []\nParameterSets:\n- N
1ame: (All)\n Position: 0\n IsRequired: true\n ValueFromPipeline: false\n ValueFromPipelineByPropertyName: false\n ValueFromRemainingArguments: false\nDontShow: false\nAcceptedValues: []\nHelpMessage: ''\n"})}),"\n",(0,l.jsx)(n.h3,{id:"-scriptblock",children:"-ScriptBlock"}),"\n",(0,l.jsx)(n.p,{children:"The code to be executed within the script module."}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-yaml",children:"Type: System.Management.Automation.ScriptBlock\nDefaultValue: ''\nSupportsWildcards: false\nAliases: []\nParameterSets:\n- Name: (All)\n Position: 1\n IsRequired: true\n ValueFromPipeline: false\n ValueFromPipelineByPropertyName: false\n ValueFromRemainingArguments: false\nDontShow: false\nAcceptedValues: []\nHelpMessage: ''\n"})}),"\n",(0,l.jsx)(n.h3,{id:"commonparameters",children:"CommonParameters"}),"\n",(0,l.jsxs)(n.p,{children:["This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,\n-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,\n-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see\n",(0,l.jsx)(n.a,{href:"https://go.microsoft.com/fwlink/?LinkID=113216",children:"about_CommonParameters"}),"."]}),"\n",(0,l.jsx)(n.h2,{id:"inputs",children:"INPUTS"}),"\n",(0,l.jsx)(n.h2,{id:"outputs",children:"OUTPUTS"}),"\n",(0,l.jsx)(n.h2,{id:"notes",children:"NOTES"}),"\n",(0,l.jsx)(n.h2,{id:"related-links",children:"RELATED LINKS"}),"\n",(0,l.jsx)(n.h2,{id:"version",children:"VERSION"}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsxs)(n.em,{children:["This page was generated using comment-based help in ",(0,l.jsx)(n.a,{href:"https://github.com/pester/Pester/tree/rel/4.x.x",children:"Pester 4.10.1"}),"."]})})]})}function u(e={}){let{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,l.jsx)(n,{...e,children:(0,l.jsx)(d,{...e})}):d(e)}},7008(e,n,o){o.d(n,{R:()=>i,x:()=>r});var t=o(1763);let l={},s=t.createContext(l);function i(e){let n=t.useContext(s);return t.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(l):e.components||l:i(e.components),t.createElement(s.Provider,{value:n},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.