PageSourceSearch

https://pester.dev/assets/js/061a002d.174b39b1.js

js pester.dev collected 2026-10-03 19:38:38 UTC 9,096 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkpester_docs=self.webpackChunkpester_docs||[]).push([["4386"],{5701(e,s,t){t.r(s),t.d(s,{metadata:()=>n,default:()=>h,frontMatter:()=>r,contentTitle:()=>i,toc:()=>d,assets:()=>o});var n=JSON.parse('{"id":"commands/Should-HaveType","title":"Should-HaveType","description":"Help for Pester command \'Should-HaveType\'. Asserts that the input is of the expected type.","source":"@site/docs/commands/Should-HaveType.mdx","sourceDirName":"commands","slug":"/commands/Should-HaveType","permalink":"/docs/commands/Should-HaveType","draft":false,"unlisted":false,"editUrl":null,"tags":[],"version":"current","frontMatter":{"id":"Should-HaveType","title":"Should-HaveType","description":"Help for Pester command \'Should-HaveType\'. Asserts that the input is of the expected type.","keywords":["PowerShell","Pester","Help","Documentation"],"hide_title":false,"hide_table_of_contents":false,"custom_edit_url":null},"sidebar":"commands","previous":{"title":"Should-HaveParameter","permalink":"/docs/commands/Should-HaveParameter"},"next":{"title":"Should-Invoke","permalink":"/docs/commands/Should-Invoke"}}'),a=t(1987),l=t(7008);let r={id:"Should-HaveType",title:"Should-HaveType",description:"Help for Pester command 'Should-HaveType'. Asserts that the input is of the expected type.",keywords:["PowerShell","Pester","Help","Documentation"],hide_title:!1,hide_table_of_contents:!1,custom_edit_url:null},i,o={},d=[{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:"EXAMPLE 2",id:"example-2",level:3},{value:"PARAMETERS",id:"parameters",level:2},{value:"-Actual",id:"-actual",level:3},{value:"-Because",id:"-because",level:3},{value:"-Expected",id:"-expected",level:3},{value:"CommonParameters",id:"commonparameters",level:3},{value:"INPUTS",id:"inputs",level:2},{value:"System.Object",id:"systemobject",level:3},{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 c(e){let s={a:"a",admonition:"admonition",code:"code",em:"em",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",ul:"ul",...(0,l.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.admonition,{title:"This page was generated",type:"info",children:(0,a.jsxs)(s.p,{children:["Contributions are welcome in ",(0,a.jsx)(s.a,{href:"https://github.com/pester/pester",children:"Pester-repo"}),"."]})}),"\n",(0,a.jsx)(s.h2,{id:"synopsis",children:"SYNOPSIS"}),"\n",(0,a.jsx)(s.p,{children:"Asserts that the input is of the expected type."}),"\n",(0,a.jsx)(s.h2,{id:"syntax",children:"SYNTAX"}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-powershell",children:"Should-HaveType [-Expected] <Object> [[-Actual] <Object>] [-Because <string>]\n"})}),"\n",(0,a.jsx)(s.h2,{id:"description",children:"DESCRIPTION"}),"\n",(0,a.jsxs)(s.p,{children:["This assertion uses ",(0,a.jsx)(s.code,{children:"-is"})," to verify that the actual value is assignable to the expected type.\nDerived types and implemented interfaces also satisfy the check."]}),"\n",(0,a.jsxs)(s.p,{children:["When the expected type is given as a name that does not resolve to a loaded .NET type, the assertion falls back to matching against the actual value's ",(0,a.jsx)(s.code,{children:"PSTypeNames"}),".\nThis allows asserting against PowerShell custom types, such as objects tagged with a ",(0,a.jsx)(s.code,{children:"PSTypeName"})," or extended with ",(0,a.jsx)(s.code,{children:"Add-Member -TypeName"}),"."]}),"\n",(0,a.jsx)(s.h2,{id:"examples",children:"EXAMPLES"}),"\n",(0,a.jsx)(s.h3,{id:"example-1",children:"EXAMPLE 1"}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-powershell",children:'"hello" | Should-HaveType ([String])\n1 | Should-HaveType ([Int32])\n'})}),"\n",(0,a.jsx)(s.p,{children:"These assertions will pass, because the actual value is of the expected type."}),"\n",(0,a.jsx)(s.h3,{id:"example-2",children:"EXAMPLE 2"}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-powershell",children:"$actual = [PSCustomObject]@{ PSTypeName = 'MyApp.Person'; Name = 'Jane' }\n$actual | Should-HaveType 'MyApp.Person'\n"})}),"\n",(0,a.jsx)(s.p,{children:"This assertion will pass, because 'MyApp.Person' is not a loaded .NET type, so the actual value's PSTypeNames are checked instead."}),"\n",(0,a.jsx)(s.h2,{id:"parameters",children:"PARAMETERS"}),"\n",(0,a.jsx)(s.h3,{id:"-actual",children:"-Actual"}),"\n",(0,a.jsx)(s.p,{children:"The actual value."}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-yaml",children:"Type: System.Object\nDefaultValue: ''\nSupportsWildcards: false\nAliases: []\nParameterSets:\n- N
1ame: (All)\n  Position: 1\n  IsRequired: false\n  ValueFromPipeline: true\n  ValueFromPipelineByPropertyName: false\n  ValueFromRemainingArguments: false\nDontShow: false\nAcceptedValues: []\nHelpMessage: ''\n"})}),"\n",(0,a.jsx)(s.h3,{id:"-because",children:"-Because"}),"\n",(0,a.jsx)(s.p,{children:"The reason why the input should be the expected type."}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-yaml",children:"Type: System.String\nDefaultValue: ''\nSupportsWildcards: false\nAliases: []\nParameterSets:\n- Name: (All)\n  Position: Named\n  IsRequired: false\n  ValueFromPipeline: false\n  ValueFromPipelineByPropertyName: false\n  ValueFromRemainingArguments: false\nDontShow: false\nAcceptedValues: []\nHelpMessage: ''\n"})}),"\n",(0,a.jsx)(s.h3,{id:"-expected",children:"-Expected"}),"\n",(0,a.jsxs)(s.p,{children:["The expected type.\nProvide a ",(0,a.jsx)(s.code,{children:"[Type]"}),", a type name that resolves to a loaded .NET type, or a custom type name to match against the actual value's ",(0,a.jsx)(s.code,{children:"PSTypeNames"}),"."]}),"\n",(0,a.jsx)(s.pre,{children:(0,a.jsx)(s.code,{className:"language-yaml",children:"Type: System.Object\nDefaultValue: ''\nSupportsWildcards: false\nAliases: []\nParameterSets:\n- Name: (All)\n  Position: 0\n  IsRequired: true\n  ValueFromPipeline: false\n  ValueFromPipelineByPropertyName: false\n  ValueFromRemainingArguments: false\nDontShow: false\nAcceptedValues: []\nHelpMessage: ''\n"})}),"\n",(0,a.jsx)(s.h3,{id:"commonparameters",children:"CommonParameters"}),"\n",(0,a.jsxs)(s.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,a.jsx)(s.a,{href:"https://go.microsoft.com/fwlink/?LinkID=113216",children:"about_CommonParameters"}),"."]}),"\n",(0,a.jsx)(s.h2,{id:"inputs",children:"INPUTS"}),"\n",(0,a.jsx)(s.h3,{id:"systemobject",children:"System.Object"}),"\n",(0,a.jsx)(s.h2,{id:"outputs",children:"OUTPUTS"}),"\n",(0,a.jsx)(s.h2,{id:"notes",children:"NOTES"}),"\n",(0,a.jsxs)(s.p,{children:["Use the ",(0,a.jsx)(s.code,{children:"-ErrorAction"})," parameter to control soft-assertion behavior for this assertion.\n",(0,a.jsx)(s.code,{children:"-ErrorAction Continue"})," records the failure and lets the rest of the test run (a soft assertion), while ",(0,a.jsx)(s.code,{children:"-ErrorAction Stop"})," fails the test immediately, for example to guard a precondition before continuing."]}),"\n",(0,a.jsxs)(s.p,{children:["When ",(0,a.jsx)(s.code,{children:"-ErrorAction"})," is not specified, the behavior comes from ",(0,a.jsx)(s.code,{children:"Should.ErrorAction"})," in the configuration, which defaults to ",(0,a.jsx)(s.code,{children:"Stop"}),".\nSee ",(0,a.jsx)(s.a,{href:"https://pester.dev/docs/assertions/soft-assertions",children:"https://pester.dev/docs/assertions/soft-assertions"})," for more about soft assertions."]}),"\n",(0,a.jsx)(s.h2,{id:"related-links",children:"RELATED LINKS"}),"\n",(0,a.jsxs)(s.ul,{children:["\n",(0,a.jsx)(s.li,{children:(0,a.jsx)(s.a,{href:"https://pester.dev/docs/commands/Should-HaveType",children:"https://pester.dev/docs/commands/Should-HaveType"})}),"\n",(0,a.jsx)(s.li,{children:(0,a.jsx)(s.a,{href:"https://pester.dev/docs/assertions",children:"https://pester.dev/docs/assertions"})}),"\n"]}),"\n",(0,a.jsx)(s.h2,{id:"version",children:"VERSION"}),"\n",(0,a.jsx)(s.p,{children:(0,a.jsxs)(s.em,{children:["This page was generated using comment-based help in ",(0,a.jsx)(s.a,{href:"https://github.com/pester/pester",children:"Pester 6.1.0"}),"."]})})]})}function h(e={}){let{wrapper:s}={...(0,l.R)(),...e.components};return s?(0,a.jsx)(s,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}},7008(e,s,t){t.d(s,{R:()=>r,x:()=>i});var n=t(1763);let a={},l=n.createContext(a);function r(e){let s=n.useContext(l);return n.useMemo(function(){return"function"==typeof e?e(s):{...s,...e}},[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:r(e.components),n.createElement(l.Provider,{value:s},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.