PageSourceSearch

https://pester.dev/assets/js/9b30658f.d633b9f3.js

js pester.dev collected 2026-10-03 19:37:41 UTC 12,552 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkpester_docs=self.webpackChunkpester_docs||[]).push([["3355"],{7886(e,n,a){a.r(n),a.d(n,{metadata:()=>t,default:()=>u,frontMatter:()=>r,contentTitle:()=>o,toc:()=>c,assets:()=>i});var t=JSON.parse('{"id":"commands/Should-BeEquivalent","title":"Should-BeEquivalent","description":"Help for Pester command \'Should-BeEquivalent\'. Compares two objects for equivalency, by recursively comparing their properties for equivalency.","source":"@site/docs/commands/Should-BeEquivalent.mdx","sourceDirName":"commands","slug":"/commands/Should-BeEquivalent","permalink":"/docs/commands/Should-BeEquivalent","draft":false,"unlisted":false,"editUrl":null,"tags":[],"version":"current","frontMatter":{"id":"Should-BeEquivalent","title":"Should-BeEquivalent","description":"Help for Pester command \'Should-BeEquivalent\'. Compares two objects for equivalency, by recursively comparing their properties for equivalency.","keywords":["PowerShell","Pester","Help","Documentation"],"hide_title":false,"hide_table_of_contents":false,"custom_edit_url":null},"sidebar":"commands","previous":{"title":"Should-BeEmptyString","permalink":"/docs/commands/Should-BeEmptyString"},"next":{"title":"Should-BeFalse","permalink":"/docs/commands/Should-BeFalse"}}'),s=a(1987),l=a(7008);let r={id:"Should-BeEquivalent",title:"Should-BeEquivalent",description:"Help for Pester command 'Should-BeEquivalent'. Compares two objects for equivalency, by recursively comparing their properties for equivalency.",keywords:["PowerShell","Pester","Help","Documentation"],hide_title:!1,hide_table_of_contents:!1,custom_edit_url:null},o,i={},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:"EXAMPLE 2",id:"example-2",level:3},{value:"EXAMPLE 3",id:"example-3",level:3},{value:"EXAMPLE 4",id:"example-4",level:3},{value:"PARAMETERS",id:"parameters",level:2},{value:"-Actual",id:"-actual",level:3},{value:"-Because",id:"-because",level:3},{value:"-Comparator",id:"-comparator",level:3},{value:"-ExcludePath",id:"-excludepath",level:3},{value:"-ExcludePathsNotOnExpected",id:"-excludepathsnotonexpected",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 d(e){let n={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,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.admonition,{title:"This page was generated",type:"info",children:(0,s.jsxs)(n.p,{children:["Contributions are welcome in ",(0,s.jsx)(n.a,{href:"https://github.com/pester/pester",children:"Pester-repo"}),"."]})}),"\n",(0,s.jsx)(n.h2,{id:"synopsis",children:"SYNOPSIS"}),"\n",(0,s.jsx)(n.p,{children:"Compares two objects for equivalency, by recursively comparing their properties for equivalency."}),"\n",(0,s.jsx)(n.h2,{id:"syntax",children:"SYNTAX"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-powershell",children:"Should-BeEquivalent [-Expected] <Object> [[-Actual] <Object>] [-Because <string>]\n [-ExcludePath <string[]>] [-ExcludePathsNotOnExpected] [-Comparator <string>]\n"})}),"\n",(0,s.jsx)(n.h2,{id:"description",children:"DESCRIPTION"}),"\n",(0,s.jsxs)(n.p,{children:["This assertion performs a deep comparison of the actual and expected objects, recursing through nested properties and collections.\nUse ",(0,s.jsx)(n.code,{children:"-ExcludePath"}),", ",(0,s.jsx)(n.code,{children:"-ExcludePathsNotOnExpected"}),", or ",(0,s.jsx)(n.code,{children:"-Comparator Equality"})," to narrow what counts as equivalent."]}),"\n",(0,s.jsx)(n.h2,{id:"examples",children:"EXAMPLES"}),"\n",(0,s.jsx)(n.h3,{id:"example-1",children:"EXAMPLE 1"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-powershell",children:"Should-BeEquivalent ...  -ExcludePath 'Id', 'Timestamp' -Comparator 'Equality'\n"})}),"\n",(0,s.jsx)(n.p,{children:"This example generates an equivalency option object that excludes the 'Id' and 'Timestamp' properties from the comparison and uses a simple equality comparison strategy."}),"\n",(0,s.jsx)(n.h3,{id:"example-2",children:"EXAMPLE 2"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-powershell",children:"Should-BeEquivalent ... -ExcludePathsNotOnExpected\n"})}),"\n",(0,s.jsx)(n.p,{children:"This example generates an equivalency option object that excludes any paths not present on the expected object from the comparison, using the default deep comparison strategy."}),"\n",(0,s.jsx)(n.h3,{id:"example-3",children:"EXAMPLE 3"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-powershell",children:'$expected = [PSCustomObject] @{\n    Name = "Thomas"\n}\n\n$actual = [PSCustomObject] @{\n    Name = "Jakub"\n    Age = 30\n}\n\n$actual | Should-BeEquivalent $expected\n'})}),"\n",(0,s.jsx)(n.p,{children:"This will throw an error because the actual object has an additional property Age and the Name values are not equivalent."}),"\n",(0,s.jsx)(n.h3,{id:"example-4",children:"EXAMPLE 4"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-powershell",children:'$expected = [PSCustomObject] @{\n    Name = "Thomas"\n}\n\n$actual = [PSCustomObject] @{\n    Name = "Thomas"\n}\n\n$actual | Should-BeEquivalent $expected\n'})}),"\n",(0,s.jsx)(n.p,{children:"This will pass because the actual object has the same properties as the expected object and the Name values are equivalent."}),"\n",(0,s.jsx)(n.h2,{id:"parameters",children:"PARAMETERS"}),"\n",(0,s.jsx)(n.h3,{id:"-actual",children:"-Actual"}),"\n",(0,s.jsx)(n.p,{children:"The actual object to compare."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.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,s.jsx)(n.h3,{id:"-because",children:"-Because"}),"\n",(0,s.jsx)(n.p,{children:"The reason why the input should be the expected value."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.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,s.jsx)(n.h3,{id:"-comparator",children:"-Comparator"}),"\n",(0,s.jsx)(n.p,{children:"Specifies the comparison strategy to use.\nThe options are 'Equivalency' for a deep comparison that considers the structure and values of objects, and 'Equality' for a simple equality comparison.\nThe default is 'Equivalency'."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-yaml",children:"Type: System.String\nDefaultValue: Equivalency\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,s.jsx)(n.h3,{id:"-excludepath",children:"-ExcludePath"}),"\n",(0,s.jsx)(n.p,{children:'An array of strings specifying the paths to exclude from the comparison.\nEach path should correspond to a property name or a chain of property names separated by dots for nested properties.\nThe paths use dot notation to navigate to a child property, such as "user.name".'}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.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,s.jsx)(n.h3,{id:"-excludepathsnotonexpected",children:"-ExcludePathsNotOnExpected"}),"\n",(0,s.jsx)(n.p,{children:"A switch parameter that, when set, excludes any paths from the comparison that are not present on the expected object.\nThis is useful for ignoring extra properties on the actual object that are not relevant to the comparison."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-yaml",children:"Type: System.Management.Automation.SwitchParameter\nDefaultValue: False\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,s.jsx)(n.h3,{id:"-expected",children:"-Expected"}),"\n",(0,s.jsx)(n.p,{children:"The expected object to compare."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.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,s.jsx)(n.h3,{id:"commonparameters",children:"CommonParameters"}),"\n",(0,s.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,s.jsx)(n.a,{href:"https://go.microsoft.com/fwlink/?LinkID=113216",children:"about_CommonParameters"}),"."]}),"\n",(0,s.jsx)(n.h2,{id:"inputs",children:"INPUTS"}),"\n",(0,s.jsx)(n.h3,{id:"systemobject",children:"System.Object"}),"\n",(0,s.jsx)(n.h2,{id:"outputs",children:"OUTPUTS"}),"\n",(0,s.jsx)(n.h2,{id:"notes",children:"NOTES"}),"\n",(0,s.jsxs)(n.p,{children:["Use the ",(0,s.jsx)(n.code,{children:"-ErrorAction"})," parameter to control soft-assertion behavior for this assertion.\n",(0,s.jsx)(n.code,{children:"-ErrorAction Continue"})," records the failure and lets the rest of the test run (a soft assertion), while ",(0,s.jsx)(n.code,{children:"-ErrorAction Stop"})," fails the test immediately, for example to guard a precondition before continuing."]}),"\n",(0,s.jsxs)(n.p,{children:["When ",(0,s.jsx)(n.code,{children:"-ErrorAction"})," is not specified, the behavior comes from ",(0,s.jsx)(n.code,{children:"Should.ErrorAction"})," in the configuration, which defaults to ",(0,s.jsx)(n.code,{children:"Stop"}),".\nSee ",(0,s.jsx)(n.a,{href:"https://pester.dev/docs/assertions/soft-assertions",children:"https://pester.dev/docs/assertions/soft-assertions"})," for more about soft assertions."]}),"\n",(0,s.jsx)(n.h2,{id:"related-links",children:"RELATED LINKS"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"https://pester.dev/docs/commands/Should-BeEquivalent",children:"https://pester.dev/docs/commands/Should-BeEquivalent"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"https://pester.dev/docs/assertions",children:"https://pester.dev/docs/assertions"})}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"version",children:"VERSION"}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.em,{children:["This page was generated using comment-based help in ",(0,s.jsx)(n.a,{href:"https://github.com/pester/
1pester",children:"Pester 6.1.0"}),"."]})})]})}function u(e={}){let{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},7008(e,n,a){a.d(n,{R:()=>r,x:()=>o});var t=a(1763);let s={},l=t.createContext(s);function r(e){let n=t.useContext(l);return t.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),t.createElement(l.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.