-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(matcher): add
toContainEntries
matcher
- Loading branch information
1 parent
8005015
commit beb20b2
Showing
6 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2021-Present the Unitest authors. All rights reserved. MIT license. | ||
// This module is browser compatible. | ||
|
||
import { containAll } from "./utils.ts"; | ||
import type { MatchResult } from "./types.ts"; | ||
|
||
function toContainEntries( | ||
actual: object, | ||
expected: [string, unknown][], | ||
): MatchResult { | ||
const entries = Object.entries(actual); | ||
|
||
return { | ||
pass: containAll(entries, expected), | ||
actual: entries, | ||
actualHint: "Actual entries:", | ||
expected, | ||
expectedHint: "Expected to contain all:", | ||
}; | ||
} | ||
|
||
export { toContainEntries }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2021-Present the Unitest authors. All rights reserved. MIT license. | ||
|
||
import { assertEquals, assertFail, assertSuccess } from "../dev_deps.ts"; | ||
import { toContainEntries } from "./to_contain_entries.ts"; | ||
|
||
Deno.test({ | ||
name: "toContainEntries", | ||
fn: () => { | ||
assertSuccess(toContainEntries({}, [])); | ||
assertSuccess(toContainEntries({ a: 1 }, [["a", 1]])); | ||
assertSuccess( | ||
toContainEntries({ a: 1, b: "", c: {} }, [["c", {}], ["a", 1]]), | ||
); | ||
assertFail( | ||
toContainEntries({ a: 1, b: "", c: {} }, [["c", {}], ["a", 1], [ | ||
"d", | ||
null, | ||
]]), | ||
); | ||
|
||
assertEquals(toContainEntries({ a: 1 }, [["a", 1], ["b", 2], ["c", "3"]]), { | ||
pass: false, | ||
actual: [["a", 1]], | ||
actualHint: "Actual entries:", | ||
expected: [["a", 1], ["b", 2], ["c", "3"]], | ||
expectedHint: "Expected to contain all:", | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters