Skip to content

Commit

Permalink
Replace complex test with inline snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
rekmarks committed May 12, 2022
1 parent 4b90ca4 commit 931bd2a
Showing 1 changed file with 28 additions and 36 deletions.
64 changes: 28 additions & 36 deletions src/collections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@ describe('FrozenMap', () => {
describe('immutability', () => {
it('has the expected class properties', () => {
// i.e., does not have 'delete', 'set', or 'clear'
const expectedProperties = new Set([
'constructor',
'entries',
'forEach',
'get',
'has',
'keys',
'size',
'values',
'toString',
]);

const properties = Object.getOwnPropertyNames(FrozenMap.prototype);

expect(properties).toHaveLength(expectedProperties.size);
properties.forEach((propertyName) =>
expect(expectedProperties.has(propertyName)).toBe(true),
);
expect(Object.getOwnPropertyNames(FrozenMap.prototype))
.toMatchInlineSnapshot(`
Array [
"constructor",
"size",
"entries",
"forEach",
"get",
"has",
"keys",
"values",
"toString",
]
`);
});

it('is frozen and cannot be mutated', () => {
Expand Down Expand Up @@ -95,7 +91,7 @@ describe('FrozenMap', () => {
]);

frozenMap.forEach((value, key) => {
expect(expected.get(key)).toStrictEqual(value);
expect(value).toStrictEqual(expected.get(key));
expected.delete(key);
});

Expand Down Expand Up @@ -235,23 +231,19 @@ describe('FrozenSet', () => {
describe('immutability', () => {
it('has the expected class properties', () => {
// i.e., does not have 'delete', 'add', or 'clear'
const expectedProperties = new Set([
'constructor',
'entries',
'forEach',
'has',
'keys',
'size',
'toString',
'values',
]);

const properties = Object.getOwnPropertyNames(FrozenSet.prototype);

expect(properties).toHaveLength(expectedProperties.size);
properties.forEach((propertyName) =>
expect(expectedProperties.has(propertyName)).toBe(true),
);
expect(Object.getOwnPropertyNames(FrozenSet.prototype))
.toMatchInlineSnapshot(`
Array [
"constructor",
"size",
"entries",
"forEach",
"has",
"keys",
"values",
"toString",
]
`);
});

it('is frozen and cannot be mutated', () => {
Expand Down

0 comments on commit 931bd2a

Please sign in to comment.