-
-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathinvert.test.js
More file actions
25 lines (21 loc) · 793 Bytes
/
invert.test.js
File metadata and controls
25 lines (21 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const invert = require("./invert");
test("invert returns an object with keys and values swapped, simple case", () => {
const input = { a: 1 };
const expectedOutput = { 1: "a" };
expect(invert(input)).toEqual(expectedOutput);
});
test("invert returns an object with keys and values swapped, multiple pairs", () => {
const input = { a: 1, b: 2 };
const expectedOutput = { 1: "a", 2: "b" };
expect(invert(input)).toEqual(expectedOutput);
});
test("invert handles empty objects", () => {
const input = {};
const expectedOutput = {};
expect(invert(input)).toEqual(expectedOutput);
});
test("invert handles non-string values", () => {
const input = { x: true, y: null };
const expectedOutput = { true: "x", null: "y" };
expect(invert(input)).toEqual(expectedOutput);
});