1"use strict";(self.webpackChunkpester_docs=self.webpackChunkpester_docs||[]).push([["5771"],{5811(e,n,t){t.r(n),t.d(n,{metadata:()=>s,default:()=>h,frontMatter:()=>i,contentTitle:()=>a,toc:()=>c,assets:()=>r});var s=JSON.parse('{"id":"commands/Should-ContainCollection","title":"Should-ContainCollection","description":"Help for Pester command \'Should-ContainCollection\'. Checks that the expected collection is present in the actual collection as an ordered subsequence. It does not compare the types of the input collections.","source":"@site/docs/commands/Should-ContainCollection.mdx","sourceDirName":"commands","slug":"/commands/Should-ContainCollection","permalink":"/docs/commands/Should-ContainCollection","draft":false,"unlisted":false,"editUrl":null,"tags":[],"version":"current","frontMatter":{"id":"Should-ContainCollection","title":"Should-ContainCollection","description":"Help for Pester command \'Should-ContainCollection\'. Checks that the expected collection is present in the actual collection as an ordered subsequence. It does not compare the types of the input collections.","keywords":["PowerShell","Pester","Help","Documentation"],"hide_title":false,"hide_table_of_contents":false,"custom_edit_url":null},"sidebar":"commands","previous":{"title":"Should-BeTruthy","permalink":"/docs/commands/Should-BeTruthy"},"next":{"title":"Should-HaveParameter","permalink":"/docs/commands/Should-HaveParameter"}}'),o=t(1987),l=t(7008);let i={id:"Should-ContainCollection",title:"Should-ContainCollection",description:"Help for Pester command 'Should-ContainCollection'. Checks that the expected collection is present in the actual collection as an ordered subsequence. It does not compare the types of the input collections.",keywords:["PowerShell","Pester","Help","Documentation"],hide_title:!1,hide_table_of_contents:!1,custom_edit_url:null},a,r={},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:"PARAMETERS",id:"parameters",level:2},{value:"-Actual",id:"-actual",level:3},{value:"-Because",id:"-because",level:3},{value:"-Expected",id:"-expected",level:3},{value:"-IgnoreOrder",id:"-ignoreorder",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,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.admonition,{title:"This page was generated",type:"info",children:(0,o.jsxs)(n.p,{children:["Contributions are welcome in ",(0,o.jsx)(n.a,{href:"https://github.com/pester/pester",children:"Pester-repo"}),"."]})}),"\n",(0,o.jsx)(n.h2,{id:"synopsis",children:"SYNOPSIS"}),"\n",(0,o.jsx)(n.p,{children:"Checks that the expected collection is present in the actual collection as an ordered subsequence. It does not compare the types of the input collections."}),"\n",(0,o.jsx)(n.h2,{id:"syntax",children:"SYNTAX"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-powershell",children:"Should-ContainCollection [-Expected] <Object> [[-Actual] <Object>] [-IgnoreOrder]\n [-Because <string>]\n"})}),"\n",(0,o.jsx)(n.h2,{id:"description",children:"DESCRIPTION"}),"\n",(0,o.jsxs)(n.p,{children:["The items of the expected collection must appear in the actual collection in the same order.\nGaps between the matched items are allowed, but each actual item is used at most once, so repeated expected items need at least as many matching items in the actual collection.\nA single value is treated as a one-item collection.\nItems are compared using PowerShell equality, the same as the ",(0,o.jsx)(n.code,{children:"-contains"})," operator."]}),"\n",(0,o.jsxs)(n.p,{children:["Use ",(0,o.jsx)(n.code,{children:"-IgnoreOrder"})," to check that the expected items are present in any order.\nEach actual item is still used at most once, so repeated expected items need at least as many matching items in the actual collection."]}),"\n",(0,o.jsx)(n.h2,{id:"examples",children:"EXAMPLES"}),"\n",(0,o.jsx)(n.h3,{id:"example-1",children:"EXAMPLE 1"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-powershell",children:"1, 2, 3 | Should-ContainCollection @(1, 2)\n1, 2, 3 | Should-ContainCollection @(1, 3)\n@(1) | Should-ContainCollection @(1)\n1, 2, 3 | Should-ContainCollection 2\n"})}),"\n",(0,o.jsxs)(n.p,{children:["These assertions pass, because the expected items are present in the same order.\nGaps between them, as in ",(0,o.jsx)(n.code,{children:"@(1, 3)"}),", are allowed, and a single value is treated as a one-item collection."]}),"\n",(0,o.jsx)(n.h3,{id:"example-2",children:"EXAMPLE 2"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-powershell",children:"'b', 3, 2, 'a' | Should-ContainCollection @('a', 2) -IgnoreOrder\n1, 2, 3 | Should-ContainCollection @(3, 2, 1) -IgnoreOrder\n"})}),"\n",(0,o.jsxs)(n.p,{children:["These assertions pass, because with ",(0,o.jsx)(n.code,{children:"-IgnoreOrder"})," the expected items only need to be present, not in any particular order."]}),"\n",(0,o.jsx)(n.h3,{id:"example-3",children:"EXAMPLE 3"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-powershell",children:"1, 2, 3 | Should-ContainCollection @(3, 4)\n1, 2, 3 | Should-ContainCollection @(3, 2, 1)\n1, 2 | Should-ContainCollection @(1, 1)\n@(1) | Should-ContainCollection @(2)\n"})}),"\n",(0,o.jsxs)(n.p,{children:["These assertions fail, because an expected item is missing (",(0,o.jsx)(n.code,{children:"@(3, 4)"}),"), the items are not in the right order (",(0,o.jsx)(n.code,{children:"@(3, 2, 1)"}),"), or the actual collection does not have enough matching items (",(0,o.jsx)(n.code,{children:"@(1, 1)"})," needs two 1s)."]}),"\n",(0,o.jsx)(n.h2,{id:"parameters",children:"PARAMETERS"}),"\n",(0,o.jsx)(n.h3,{id:"-actual",children:"-Actual"}),"\n",(0,o.jsx)(n.p,{children:"The collection to search in."}),"\n",(0,o.jsx)(n.pre,{children:(0,o.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,o.jsx)(n.h3,{id:"-because",children:"-Because"}),"\n",(0,o.jsx)(n.p,{children:"The reason why the input should be the expected value."}),"\n",(0,o.jsx)(n.pre,{children:(0,o.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,o.jsx)(n.h3,{id:"-expected",children:"-Expected"}),"\n",(0,o.jsxs)(n.p,{children:["One or more items to look for.\nBy default they must appear as an ordered subsequence; with ",(0,o.jsx)(n.code,{children:"-IgnoreOrder"})," the order does not matter.\nA single value is treated as a one-item collection."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.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,o.jsx)(n.h3,{id:"-ignoreorder",children:"-IgnoreOrder"}),"\n",(0,o.jsx)(n.p,{children:"Ignores the order of the items, so the expected items only need to be present in the actual collection, in any order."}),"\n",(0,o.jsx)(n.pre,{children:(0,o.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,o.jsx)(n.h3,{id:"commonparameters",children:"CommonParameters"}),"\n",(0,o.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,o.jsx)(n.a,{href:"https://go.microsoft.com/fwlink/?LinkID=113216",children:"about_CommonParameters"}),"."]}),"\n",(0,o.jsx)(n.h2,{id:"inputs",children:"INPUTS"}),"\n",(0,o.jsx)(n.h3,{id:"systemobject",children:"System.Object"}),"\n",(0,o.jsx)(n.h2,{id:"outputs",children:"OUTPUTS"}),"\n",(0,o.jsx)(n.h2,{id:"notes",children:"NOTES"}),"\n",(0,o.jsxs)(n.p,{children:["Use the ",(0,o.jsx)(n.code,{children:"-ErrorAction"})," parameter to control soft-assertion behavior for this assertion.\n",(0,o.jsx)(n.code,{children:"-ErrorAction Continue"})," records the failure and lets the rest of the test run (a soft assertion), while ",(0,o.jsx)(n.code,{children:"-ErrorAction Stop"})," fails the test immediately, for example to guard a precondition before continuing."]}),"\n",(0,o.jsxs)(n.p,{children:["When ",(0,o.jsx)(n.code,{children:"-ErrorAction"})," is not specified, the behavior comes from ",(0,o.jsx)(n.code,{children:"Should.ErrorAction"})," in the configuration, which defaults to ",(0,o.jsx)(n.code,{children:"Stop"}),".\nSee ",(0,o.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,o.jsx)(n.h2,{id:"related-links",children:"RELATED LINKS"}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsx)(n.li,{children:(0,o.jsx)(n.a,{href:"https://pester.dev/docs/commands/Should-ContainCollection",children:"https://pester.dev/docs/commands/Should-ContainCollection"})}),"\n",(0,o.jsx)(n.li,{children:(0,o.jsx)(n.a,{href:"https://pester.dev/docs/assertions",children:"https://pester.dev/docs/assertions"})}),"\n"]}),"\n",(0,o.jsx)(n.h2,{id:"version",children:"VERSION"}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsxs)(n.em,{children:["This page was generated using comment-based help in ",(0,o.jsx)(n.a,{href:"https://github.com/pester/
1pester",children:"Pester 6.1.0"}),"."]})})]})}function h(e={}){let{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},7008(e,n,t){t.d(n,{R:()=>i,x:()=>a});var s=t(1763);let o={},l=s.createContext(o);function i(e){let n=s.useContext(l);return s.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),s.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.