Skip to content

Commit

Permalink
chore(tests): tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
Celtian committed Oct 22, 2024
1 parent c7c0e11 commit 653780b
Show file tree
Hide file tree
Showing 17 changed files with 2,999 additions and 496 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Thumbs.db

# Temporary files
version.ts
.swc
17 changes: 3 additions & 14 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,13 @@
"builder": "@angular-devkit/build-angular:extract-i18n"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"builder": "@angular-devkit/build-angular:jest",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "projects/demo/tsconfig.spec.json",
"inlineStyleLanguage": "scss",
"assets": [
{
"glob": "**/*",
"input": "projects/demo/public"
}
],
"styles": [
"projects/demo/src/styles.scss"
],
"scripts": []
"tsConfig": "projects/demo/tsconfig.spec.json"
}
},
"lint": {
Expand Down Expand Up @@ -152,7 +141,7 @@
"defaultConfiguration": "production"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"builder": "@angular-devkit/build-angular:jest",
"options": {
"tsConfig": "projects/ngx-nullable/tsconfig.spec.json",
"polyfills": [
Expand Down
34 changes: 34 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { swcAngularJestTransformer } from '@jscutlery/swc-angular-preset';
import type { Config } from 'jest';

const config: Config = {
clearMocks: true,
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
testEnvironment: 'jsdom',
testMatch: ['<rootDir>/projects/demo/src/app/**/*.spec.ts', '<rootDir>/projects/ngx-nullable/src/lib/**/*.spec.ts'],
collectCoverageFrom: [
'<rootDir>/projects/ngx-nullable/src/lib/**/*.ts',
'!<rootDir>/projects/ngx-nullable/src/lib/**/index.ts'
],
moduleNameMapper: {
'projects/ngx-nullable/src/public-api': '<rootDir>/projects/ngx-nullable/src/public-api'
},
transform: {
'^.+\\.(ts|mjs|js)$': swcAngularJestTransformer(),
'^.+\\.(html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$'
}
]
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
testPathIgnorePatterns: ['<rootDir>/dist/']
};

export default config;
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build": "ng build ngx-nullable --configuration production",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"test:jest": "jest",
"lint": "ng lint",
"script:create-version": "yarn tsx ./scripts/create-version.ts",
"script:sync-projects": "yarn tsx ./scripts/sync-projects.ts",
Expand Down Expand Up @@ -50,22 +51,24 @@
"@angular/compiler-cli": "^18.2.0",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-angular": "^19.5.0",
"@jscutlery/swc-angular-preset": "^0.3.0",
"@jscutlery/swc-plugin-angular": "^0.11.0",
"@swc/core": "~1.4.0",
"@swc/jest": "^0.2.36",
"@types/fs-extra": "^11.0.4",
"@types/jasmine": "~5.1.0",
"@types/jest": "^29.5.13",
"@types/node": "^22.7.8",
"angular-eslint": "18.4.0",
"auto-changelog": "^2.5.0",
"eslint": "^9.13.0",
"fs-extra": "^11.2.0",
"husky": "^9.1.6",
"jasmine-core": "~5.2.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"jest": "^29.7.0",
"jest-preset-angular": "^14.2.4",
"lint-staged": "^15.2.10",
"ng-packagr": "^18.2.0",
"prettier": "^3.3.3",
"ts-node": "^10.9.2",
"tsx": "^4.19.1",
"typescript": "~5.5.2",
"typescript-eslint": "8.10.0"
Expand Down
200 changes: 181 additions & 19 deletions projects/demo/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,181 @@
<ul>
<li>{{ -1000 | ngxNullable }}</li>
<li>{{ 1000 | ngxNullable }}</li>
<li>{{ 0 | ngxNullable }}</li>
<li>{{ null | ngxNullable }}</li>
<li>{{ undefined | ngxNullable }}</li>
<li>{{ 'string' | ngxNullable }}</li>
<li>{{ '' | ngxNullable }}</li>
<li>{{ ' ' | ngxNullable }}</li>
</ul>

<ul>
<li>{{ ['', ' ', undefined, null] | ngxNullableJoin }}</li>
<li>{{ ['AAA', 'BBB', 'CCC'] | ngxNullableJoin }}</li>
<li>{{ ['AAA', '', ' ', undefined, null, 'BBB'] | ngxNullableJoin }}</li>
<li>{{ [] | ngxNullableJoin }}</li>
</ul>

<div>{{ computed() }}</div>
<!-- Toolbar -->
<div class="toolbar" role="banner">
<img
width="40"
alt="Angular Logo"
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg=="
/>
<span>{{ title }}</span>
<div class="spacer"></div>
<a
class="github-logo"
aria-label="On Github"
target="_blank"
rel="noopener"
href="https://github.com/celtian/ngx-nullable"
title="Github"
>
<svg
id="github-logo"
aria-hidden="true"
height="24"
focusable="false"
data-prefix="fab"
data-icon="github"
class="svg-inline--fa fa-github fa-w-16"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 496 512"
>
<path
fill="#ffffff"
d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"
></path>
</svg>
</a>
</div>

<div class="content" role="main">
<!-- Highlight Card -->
<div class="card highlight-card card-small">
<svg viewBox="0 0 250 250" height="250" width="250" alt="Rocket Ship" id="rocket">
<defs id="defs10" />
<g id="g4546" transform="scale(2.4587423)" style="display: inline">
<circle
style="display: inline; fill: #dd0031"
r="50.839001"
cy="50.839001"
cx="50.839001"
data-name="Ellipse 8"
id="Ellipse_8"
/>
</g>
<path
id="path836"
style="
display: inline;
opacity: 1;
fill: #ffffff;
fill-opacity: 1;
stroke: none;
stroke-width: 26.6783;
stroke-linecap: round;
stroke-linejoin: round;
stroke-opacity: 1;
"
d="M 124.37305,38.945312 A 86.055979,86.055979 0 0 0 38.945312,125.00195 86.055979,86.055979 0 0 0 56.597656,177.2168 l 16.984375,-18.53711 a 61.468557,61.468557 0 0 1 -10.048828,-33.67774 61.468557,61.468557 0 0 1 61.050777,-61.468747 61.468557,61.468557 0 0 1 0.41797,0 61.468557,61.468557 0 0 1 29.07032,7.308594 l 16.98437,-18.535156 a 86.055979,86.055979 0 0 0 -46.05469,-13.361329 86.055979,86.055979 0 0 0 -0.6289,0 z m 69.42773,34.361329 -17.01758,18.572265 a 61.468557,61.468557 0 0 1 9.6875,33.123044 61.468557,61.468557 0 0 1 -61.46875,61.46875 61.468557,61.468557 0 0 1 -28.484372,-6.99804 L 79.5,198.04297 a 86.055979,86.055979 0 0 0 45.50195,13.01562 86.055979,86.055979 0 0 0 86.05664,-86.05664 86.055979,86.055979 0 0 0 -17.25781,-51.695309 z"
/>
<g id="g1034" transform="rotate(-47.5,125,125)" style="display: inline; fill: #ffffff">
<path
style="
display: inline;
fill: #ffffff;
fill-opacity: 1;
stroke: none;
stroke-width: 0.299333px;
stroke-linecap: butt;
stroke-linejoin: miter;
stroke-opacity: 1;
"
d="M 60,135 95,95 H 25 Z"
id="path1018"
/>
<path
style="
display: inline;
fill: #ffffff;
fill-opacity: 1;
stroke: none;
stroke-width: 0.299333px;
stroke-linecap: butt;
stroke-linejoin: miter;
stroke-opacity: 1;
"
d="m 190,115 35,40 h -70 z"
id="path1020"
/>
</g>
</svg>

<span>{{ title }} v{{ version.TAG }}</span>

<svg
id="rocket-smoke"
alt="Rocket Ship Smoke"
xmlns="http://www.w3.org/2000/svg"
width="516.119"
height="1083.632"
viewBox="0 0 516.119 1083.632"
>
<path
id="Path_40"
data-name="Path 40"
d="M644.6,141S143.02,215.537,147.049,870.207s342.774,201.755,342.774,201.755S404.659,847.213,388.815,762.2c-27.116-145.51-11.551-384.124,271.9-609.1C671.15,139.365,644.6,141,644.6,141Z"
transform="translate(-147.025 -140.939)"
fill="#f5f5f5"
/>
</svg>
</div>

<!-- Introduction -->
<h2>Let's nullable the value!</h2>
<p>This library provides a way to make properties nullable in Angular templates.</p>

<ul class="nullable-block" style="margin-top: 1rem">
<li>{{ -1000 | ngxNullable }}</li>
<li>{{ 1000 | ngxNullable }}</li>
<li>{{ 0 | ngxNullable }}</li>
<li>{{ null | ngxNullable }}</li>
<li>{{ undefined | ngxNullable }}</li>
<li>{{ 'string' | ngxNullable }}</li>
<li>{{ '' | ngxNullable }}</li>
<li>{{ ' ' | ngxNullable }}</li>
</ul>

<ul class="nullable-block">
<li>{{ ['', ' ', undefined, null] | ngxNullableJoin }}</li>
<li>{{ ['AAA', 'BBB', 'CCC'] | ngxNullableJoin }}</li>
<li>{{ ['AAA', '', ' ', undefined, null, 'BBB'] | ngxNullableJoin }}</li>
<li>{{ [] | ngxNullableJoin }}</li>
</ul>

<div>{{ computed() }}</div>

<!-- Footer -->
<footer>
Love this package?&nbsp;
<a href="https://github.com/Celtian/ngx-nullable" target="_blank" rel="noopener">
Give our repo a star.
<div class="github-star-badge">
<svg class="material-icons" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z" />
</svg>
Star
</div>
</a>
<a href="https://github.com/Celtian/ngx-nullable" target="_blank" rel="noopener">
<svg class="material-icons" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" fill="#1976d2" />
<path d="M0 0h24v24H0z" fill="none" />
</svg>
</a>
</footer>

<svg
id="clouds"
alt="Gray Clouds Background"
xmlns="http://www.w3.org/2000/svg"
width="2611.084"
height="485.677"
viewBox="0 0 2611.084 485.677"
>
<path
id="Path_39"
data-name="Path 39"
d="M2379.709,863.793c10-93-77-171-168-149-52-114-225-105-264,15-75,3-140,59-152,133-30,2.83-66.725,9.829-93.5,26.25-26.771-16.421-63.5-23.42-93.5-26.25-12-74-77-130-152-133-39-120-212-129-264-15-54.084-13.075-106.753,9.173-138.488,48.9-31.734-39.726-84.4-61.974-138.487-48.9-52-114-225-105-264,15a162.027,162.027,0,0,0-103.147,43.044c-30.633-45.365-87.1-72.091-145.206-58.044-52-114-225-105-264,15-75,3-140,59-152,133-53,5-127,23-130,83-2,42,35,72,70,86,49,20,106,18,157,5a165.625,165.625,0,0,0,120,0c47,94,178,113,251,33,61.112,8.015,113.854-5.72,150.492-29.764a165.62,165.62,0,0,0,110.861-3.236c47,94,178,113,251,33,31.385,4.116,60.563,2.495,86.487-3.311,25.924,5.806,55.1,7.427,86.488,3.311,73,80,204,61,251-33a165.625,165.625,0,0,0,120,0c51,13,108,15,157-5a147.188,147.188,0,0,0,33.5-18.694,147.217,147.217,0,0,0,33.5,18.694c49,20,106,18,157,5a165.625,165.625,0,0,0,120,0c47,94,178,113,251,33C2446.709,1093.793,2554.709,922.793,2379.709,863.793Z"
transform="translate(142.69 -634.312)"
fill="#eee"
/>
</svg>
</div>
Loading

0 comments on commit 653780b

Please sign in to comment.