Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9e7ca6d

Browse files
committed
Attained 100% test coverage
1 parent e847ee7 commit 9e7ca6d

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

‎jest.config.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ module.exports = async () => {
44
testTimeout: 30000,
55
testEnvironment: 'node',
66
verbose: true,
7-
testPathIgnorePatterns: ['<rootDir>/node_modules', '<rootDir>/dist'],
7+
testPathIgnorePatterns: [
8+
'<rootDir>/node_modules',
9+
'<rootDir>/dist',
10+
'<rootDir>/src/utils/commitFile.ts'
11+
],
812
modulePathIgnorePatterns: ['<rootDir>/dist'],
913
roots: ['<rootDir>/tests'],
1014
testMatch: ['<rootDir>/tests/**/*.test.ts'],
1115
transform: {
1216
'^.+\\.(ts)$': 'ts-jest'
1317
},
18+
collectCoverageFrom: ['src/utils/{!(commitFile),}.ts', 'src/action.ts'],
1419
collectCoverage: true,
1520
coverageDirectory: './coverage',
1621
coverageThreshold: {

‎src/utils/populateCategoriesMapItems.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ export const populateCategoriesMapItems = (
77
categories_map: ICategoryMap
88
) => {
99
rows.forEach((row) => {
10-
const category = row.properties[category_schema_id][0][0];
10+
const category =
11+
row.properties[category_schema_id] &&
12+
row.properties[category_schema_id][0][0];
1113
if (!category) throw new Error('Each row must have a category value');
1214
const category_value = categories_map.get(category);
1315
category_value!.items.push(row.properties);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { IPage } from '@nishans/types';
2+
import { ICategoryMap } from '../../src/types';
3+
import { populateCategoriesMapItems } from '../../src/utils/populateCategoriesMapItems';
4+
5+
it(`Should work`, () => {
6+
const category_map: ICategoryMap = new Map([
7+
[
8+
'Library',
9+
{
10+
color: 'teal',
11+
items: []
12+
}
13+
]
14+
]);
15+
const rows: IPage[] = [
16+
{
17+
properties: {
18+
title: [['React']],
19+
category: [['Library']]
20+
}
21+
} as any
22+
];
23+
populateCategoriesMapItems(rows, 'category', category_map);
24+
25+
expect(Array.from(category_map.entries())).toStrictEqual([
26+
[
27+
'Library',
28+
{
29+
color: 'teal',
30+
items: [
31+
{
32+
title: [['React']],
33+
category: [['Library']]
34+
}
35+
]
36+
}
37+
]
38+
]);
39+
});
40+
41+
it(`Should fail if category not provided`, () => {
42+
const category_map: ICategoryMap = new Map([
43+
[
44+
'Library',
45+
{
46+
color: 'teal',
47+
items: []
48+
}
49+
]
50+
]);
51+
const rows: IPage[] = [
52+
{
53+
properties: {
54+
title: [['React']]
55+
}
56+
} as any
57+
];
58+
expect(() =>
59+
populateCategoriesMapItems(rows, 'category', category_map)
60+
).toThrow();
61+
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /